2015年9月2日 星期三

[C] Send message to syslogd


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

/*
 *  * logmessage
 *   *
 *    */
void logmessage(char *logheader, char *fmt, ...)
{
  va_list args;
  char buf[512];

  va_start(args, fmt);

  vsnprintf(buf, sizeof(buf), fmt, args);
  openlog(logheader, 0, 0);
  syslog(0, buf);
  closelog();
  va_end(args);
}

int main()
{
    logmessage("HAHA", "write error : %s\n", "happy");    
}

Test :
journalctl | grep happy
Sep 02 19:32:50 freeman HAHA[6738]: write error : happy

Reference:

0 意見:

張貼留言