#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