Hello I am trying to write a basic program that uses the syslog API to log information but I am having problems with it, it does not write to any of the files I specify. The program is just something bare bones that I threw together in order to learn to use syslog. I have changed my /etc/syslog.conf file more than a few times and changed the priority and facility of the syslog function a few times. Here is my code:
Here is my syslog.conf:
As you can see all messages with the LOG_NOTICE level should be logged to /var/log/messages. This is not happening though and I have run my syslog program as root thinking it was a permissions issue but nothing shows up in /var/log/messages. I have changed the files around and changed both the facility and level of the syslog messages and sometimes I will get something printed to /dev/console (due to having the LOG_CONS option, which causes it to print to /dev/console on error) but that is about it.
Code:
#include <stdio.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
openlog("syslog_process", LOG_CONS | LOG_PID, LOG_DAEMON);
syslog(LOG_NOTICE, "Hello from Syslog");
closelog();
return 0;
}
Here is my syslog.conf:
Code:
# $FreeBSD: releng/10.3/etc/syslog.conf 260519 2014-01-10 17:56:23Z asomers $
#
# Spaces ARE valid field separators in this file. However,
# other *nix-like systems still insist on using tabs as field
# separators. If you are sharing this file between systems, you
# may want to use only tabs as field separators here.
# Consult the syslog.conf(5) manpage.
*.err;kern.warning;auth.notice;mail.crit /dev/console
*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err /var/log/messages
security.* /var/log/security
auth.info;authpriv.info /var/log/auth.log
mail.info /var/log/maillog
lpr.info /var/log/lpd-errs
ftp.info /var/log/xferlog
cron.* /var/log/cron
!-devd
*.=debug /var/log/debug.log
*.emerg *
# uncomment this to log all writes to /dev/console to /var/log/console.log
# touch /var/log/console.log and chmod it to mode 600 before it will work
#console.info /var/log/console.log
# uncomment this to enable logging of all log messages to /var/log/all.log
# touch /var/log/all.log and chmod it to mode 600 before it will work
#*.* /var/log/all.log
# uncomment this to enable logging to a remote loghost named loghost
#*.* @loghost
# uncomment these if you're running inn
# news.crit /var/log/news/news.crit
# news.err /var/log/news/news.err
# news.notice /var/log/news/news.notice
# Uncomment this if you wish to see messages produced by devd
# !devd
# *.>=notice /var/log/devd.log
!ppp
*.* /var/log/ppp.log
!*