Search code examples
c++parameter-passingsyslog

passing variable parameter list to syslog


I try to pass a variable parameter list to another function. There is already a very similary question: How to pass variable number of arguments to printf/sprintf But for me it doesn't work. And I don't know why. This is my function:

void printSyslogNotice(const char *fmt, ...)
{
      va_list ap;
      va_start(ap, fmt);
      #ifdef __XENO__
         rt_syslog(LOG_NOTICE, fmt, ap);
      #else
         syslog(LOG_NOTICE, fmt, ap);
      #endif
      va_end(ap);
}

When I call it with:

printSyslogNotice("%s %i", "hello world", 5);

I get this output: #010 -939524064

Needless to say, I would like this output: hello world 5

Does somebody has an idea?


Solution

  • You should use vsyslog, not syslog. syslog receives variable parameters pack, but not va_list. If you want to call syslog you should pass arguments as is, not by va_list.