Search code examples
clinuxsyslogrsyslog

syslog not logging my program log entries


I tried logging from my C program, but I'm not finding anything entries from my program in /var/log/messages. There are other recent entries there.

I'm using Fedora 17: Linux appliance.localdomain 3.5.3-1.fc17.i686 #1 SMP Wed Aug 29 19:25:38 UTC 2012 i686 i686 i386 GNU/Linux

I see this logging package installed: rsyslog-5.8.10-2.fc17.i686

myprompt: rpm -ql rsyslog-5.8.10-2.fc17.i686 | grep conf$

/etc/rsyslog.conf

In /etc/rsyslog.conf:

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

My code:

#include <syslog.h>
...
setlogmask (LOG_UPTO (LOG_NOTICE));
openlog ("m61", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
syslog (LOG_INFO, "In m61_init");
closelog ();

Solution

  • Your log priority mask setlogmask (LOG_UPTO (LOG_NOTICE)); discard log message bacause LOG_INFO priority level is below LOG_NOTICE.

    Priorities in order of decreasing importance

    • LOG_EMERG
    • LOG_ALERT
    • LOG_CRIT
    • LOG_ERR
    • LOG_WARNING
    • LOG_NOTICE
    • LOG_INFO
    • LOG_DEBUG

    About prioritiy

    This tells how important the content of the message is. Examples of defined priority values are: debug, informational, warning, critical. For the complete list, see syslog; vsyslog. Except for the fact that the priorities have a defined order, the meaning of each of these priorities is entirely determined by the system administrator.

    In your code change the value in setlogmask function or the priority level in syslog function.