Consider the following program:
#include <syslog.h>
int main()
{
openlog("test-app", LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);
setlogmask(LOG_UPTO(LOG_DEBUG));
syslog(LOG_DEBUG, "Testing!");
}
Note the use of LOG_PERROR
, which emits messages to stderr as well as whatever file syslogd
is configured to fill (in my case, /var/log/messages
).
test-app[28072]: Testing!
The syslog file contains:
Apr 17 13:20:14 cat test-app[28072]: Testing!
Can I configure syslog
so that the console output contains timestamps also? If so, how?