#include<syslog.h>
syslog(LOG_INFO, "Start logging");
上面的syslog命令没有登录到syslog中。所以我试着,
openlog("Logs", "", LOG_USER);
syslog(LOG_INFO, "Start logging");
closelog();
这无法记录任何内容,我得到以下错误:
syslog: unknown facility/priority: 8049584
最佳答案
这一行错了:
openlog("vyatta-conntrack", "", LOG_USER);
“”应该是整数:
void openlog(const char *ident, int option, int facility);
整数应该是这些常量中的任意一个或在一起:
LOG_CONS Write directly to system console if there is
an error while sending to system logger.
LOG_NDELAY Open the connection immediately (normally, the
connection is opened when the first message is
logged).
LOG_NOWAIT Don't wait for child processes that may have
been created while logging the message. (The
GNU C library does not create a child process,
so this option has no effect on Linux.)
LOG_ODELAY The converse of LOG_NDELAY; opening of the
connection is delayed until syslog() is
called. (This is the default, and need not be
specified.)
LOG_PERROR (Not in POSIX.1-2001.) Print to stderr as
well.
LOG_PID Include PID with each message.
再试一次,类似于:
openlog("vyatta-conntrack", LOG_PID, LOG_USER);
注意,您的
syslogd
配置可能没有设置为保留日志级别LOG_INFO
的消息。尝试LOG_ALERT
或其他方法来调试此问题——如果它有效,则返回LOG_INFO
并配置syslogd
以保留要保留的日志消息。添加一行如下:*.* /var/log/all_messages.log
将完成
rsyslogd(8)
的工作。如果您的系统使用rsyslog.conf(5)
,请务必阅读rsyslogd(8)
手册页。如果您的系统使用不同的系统日志守护程序,请查看系统的手册页以了解详细信息。