openlog():opens a connection to the system logger for a program
syslog():generates a log message, which will be distributed by syslogd(8).
LOG_PID:Include PID with each message.
LOG_CONS:Write directly to system console if there is an error while sending to system logger.
LOG_ERR:error conditions
LOG_LOCAL0 through LOG_LOCAL7:reserved for local use
#include
int main()
{
int test = 10;
openlog("MySysLogTest", LOG_PID|LOG_CONS, LOG_LOCAL7);
syslog(LOG_LOCAL7|LOG_ERR, "ERROR: just my test error msg syslog(test val=%d)\n", test);
closelog();
return 0;
}
这个小程序执行完后
/var/log/boot.log:Nov 16 11:18:08 localhost MySysLogTest[2804]: ERROR: just my test error msg syslog(test val=10)
/var/log/messages:Nov 16 11:18:08 localhost MySysLogTest[2804]: ERROR: just my test error msg syslog(test val=10)
阅读(5708) | 评论(0) | 转发(0) |