4

I'm having some trouble with <syslog.h> in 10.5. I'm writing a small fork based server for class and I want to use syslog() to print a bunch of debug info. However, I can't find any of the messages I issue via syslog() while using Console (I'm looking in both all messages & system.log).

Here is a code snippet of a plain C:

#include <syslog.h>
#include <stdarg.h>

int main (int argc, const char * argv[])
{
    openlog("Syslog Test", LOG_PID | LOG_NDELAY | LOG_CONS | LOG_PERROR, LOG_USER);
    setlogmask(LOG_UPTO(LOG_DEBUG));
    syslog(LOG_DEBUG, "%s", "Hello, World!");
    syslog(LOG_DEBUG, "%s", "And goodbye!");
    closelog();
    return 0;
}

And I don't see anything in "All Messages", "Console Messages" or system.log. Any advice?

  • 2
    Do you have syslog configured (/etc/syslog.conf) to accept debug entries? – barryj May 5 '11 at 11:05
  • It accepts debug entries from the kernal. – CyberSkull May 5 '11 at 23:03
  • Ok, so what I ended up doing for the class was just to use syslog to dump everything to the terminals I was running my server and clients from, and then save the results. I should have clarified that in the class, we were going strictly with POSIX APIs. – CyberSkull Aug 24 '11 at 10:04
5

Despite what you pass to setlogmask(), in its default configuration, OS X will only write messages to the system log that have a priority of LOG_NOTICE or higher.

Any of the following will solve your problem...

  1. Enable lower-priority logging in /etc/syslog.conf -- kern.* is not enough, as log messages from Xcode are not coming from the kernel
  2. Change the priority of your messages from LOG_DEBUG to LOG_NOTICE
  3. Simply use the built-in Xcode console -- the output will always appear there regardless of your syslog.conf settings

Here's what it looks like in the built-in Xcode 4 console:

Xcode console

Also, if you're developing exclusively for OS X, you might want to look into ASL (Apple System Log), which was meant to replace syslog().

  • I've heard of ASL, but I forgot to mention that for the purpose of the class I need to have my code be portable to Linux. – CyberSkull May 6 '11 at 3:44
  • I've also been using LOG_CONS and LOG_PERROR to dump my syslogs to the terminal I am using (Xcode & Terminal). – CyberSkull May 6 '11 at 3:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .