rsyslogd问题,使用openlog()记录,但记录到/ var / log / messages

时间:2013-07-08 12:41:54

标签: c gcc syslog libc rsyslog

我有一个代码为

的c程序
 setlogmask (LOG_UPTO (LOG_NOTICE));
 openlog ("thelog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
 syslog (LOG_NOTICE, "thelog : started by User %d", getuid ());
 syslog (LOG_INFO, "thelog: an info is logging");
 closelog();

代码工作正常但问题是日志正在记录到文件中 / var / log / messages,我有/etc/rsyslog.conf no和syslog.conf

我希望将日志记录到新文件/var/log/thelog.log文件

如何解决此问题。

2 个答案:

答案 0 :(得分:3)

如果您希望将LOCAL1记录到单独的文件

  1. 通过正确编辑其配置文件来告诉syslog
  2. 让syslogd通过发送kill -HUP重新加载其配置。
  3. 配置

    为local1添加一个特定的行,就像这个

    local1.*                -/var/log/thelog.log
    

    *.*;mail.none;news.none    -/var/log/messages
    

    并从local?。*

    的配置中删除local1
    local0.*              -/var/log/localmessages
    local2,local3.*       -/var/log/localmessages
    

    配置文件准备好后

    kill -HUP <pid-of-syslogd>
    

答案 1 :(得分:0)

You need to put this like -

local1.*                        -/var/log/myfile.log
*.*;auth,authpriv.none              -/var/log/syslog

restart syslogd service as
sudo service rsyslog restart