I'm building a C++ Linux application and I need to log its activity. What are the existing Linux facilities to create logs? What would you recommend?
+9
A:
The historic one is syslog(3). From C:
#include <syslog.h>
openlog("myprogram", LOG_PID, LOG_LOCAL0);
syslog(LOG_INFO, "data %d %s", 3, "example");
From Perl:
use Sys::Syslog;
openlog "myprogram", "pid", "local0";
syslog 'info', 'data %d %s', 3, 'example';
From shell:
logger -p local0.info -t myprogram -- data 3 example
The syslogd daemon can be configured to put log files in different places (files, tty, other machines) depending on the facility (here LOG_LOCAL0
) and the priority (here LOG_INFO
)
kmkaplan
2009-02-16 11:05:49
Can syslog write to a separate file or it all goes to the syste log?
Jack
2009-02-16 11:13:07
It goes to system log. It can also log to the console with LOG_CONS.
kmkaplan
2009-02-16 11:15:18
Yep, it's nice and easy to set up and use, although I used port to .Net of this logger (log4net).
Alex Reitbort
2009-02-16 12:06:26
+1
A:
In addition to what Alex has said, why would you need a Linux specific logger?
Amit
2009-02-16 11:32:32