syslog()用法

#include <stdio.h>
#include
<stdlib.h>
#include
<syslog.h>
#include
<fcntl.h>

int main(void)
{
int fd;
char filename[] = "/root/wenhao"; /* file is not exist */

if ((fd = open(filename, O_RDONLY)) == -1)
{
syslog(LOG_ERR
| LOG_LOCAL0, "open %s: %m\n", filename);
exit(
1);
}

return 0;
}

[root@localhost ex15_syslog]# tail -n 1 /var/log/messages

Sep  6 14:17:46 localhost syslog: open /root/wenhao: No such file or directory 

转自:http://blog.chinaunix.net/space.php?uid=20566573&do=blog&cuid=343486


原文地址:https://www.cnblogs.com/hnrainll/p/2168701.html