Using syslogd and logrotate to manage the server's log files
destination myserverlog { file("/var/log/myserverlog" owner("root") group("adm") perm(0644)); }; # TODO: made the log file readable for everyone # should be: perm(0640); filter f_myserver { facility(local0); }; # all priorities match! log { source(src); filter(f_myserver); destination(myserverlog); };
# This is the default behavior of sysklogd package # Logs may come from unix stream, but not from another machine. # source src { unix-stream("/dev/log"); internal(); file("/proc/kmsg" log_prefix("kernel: ")); };
# kill -HUP `/bin/cat /var/run/syslog-ng.pid`
$ logger -p local0.info "This is a test line"
$ tail -f /var/log/myserverlog Nov 18 20:00:55 mpino1301 logger: This is a test line
#include <syslog.h> int main(int argc, char**argv) { openlog(argv[0], /* string constant prepended to every message */ LOG_PID, /* option: include PID with each message */ LOG_LOCAL0 /* facility to log */); syslog(LOG_WARNING, "Just logged %s", "this warning."); syslog(LOG_ERR, "There were %d floating point errors.", 4711); closelog(); }