Search code examples
clinuxubuntuloggingsyslog

keeping syslog into a specific file


I use the following code below (source) to keep the log files:

#include <stdio.h>
#include <unistd.h>
#include <syslog.h>

int main(void) {

 openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
 syslog(LOG_INFO, "A different kind of Hello world ... ");
 closelog();

 return 0;
}

I run the program on ubuntu and it keeps the logs on /var/log/syslog, how can I set the logs to be kept on e.g. /var/log/mylog?


Solution

  • During openlog, use a special facility, so that you can modify your syslog.conf file to direct such logs to any log file you specified.

    Don't forget to remove such facility from the default syslog - by default all logs goes to syslog.