I use perror () to print error messages, for example:
pid = fork(); if (pid < 0) { perror("couldn't fork"); exit(EXIT_FAILURE); }
Is it possible to use objects errno/perror(), but send received messages to the system log ( /var/log/syslog)?
errno/perror()
/var/log/syslog
I ask about this in the context of a program that can be run in both daemon and non-daemon mode. In daemon mode, messages are perror()not displayed in syslog.
perror()
Use strerrorto get an error message based on the error code, without printing it. Then pass it to syslog, like any other log message:
strerror
syslog
syslog(LOG_ERR, "Couldn't fork: %s", strerror(errno));
, syslog, , . fprintf stderr , .
The easiest way is to redirect stderr (and possibly stdout) when calling your program. For example: ./myprog 2>&1 | logger.
./myprog 2>&1 | logger
Source: https://habr.com/ru/post/1619426/More articles:Is it possible to send a CQL script to a cassandra cluster through a datastax driver? - javaNew bug starting CIFAR-10 Demo with TF 0.6.0 - tensorflowError: Failed to execute Gradle execution. Reason: Unknown command line option '-X' - androidUnable to load Mod_authz_svn.so & Mod_dav_svn.so modules on-apache-2.4.10 - svnCalculation of the estimated area MKPolygon Swift - iosMySQL Transaction - update 2 tables - sqlPrinting a stack trace of C on Android 5 / Lolipop - cAngular + TypeScript + external modules. How to save file type information? - javascriptReturning a range with multiple rows with joined columns in Google Appscript - javascriptAngular JS: detect if ng-bind-html has finished loading, then highlight the syntax of the code - angularjsAll Articles