rsyslogd没有根据我的配置写入本地设施

时间:2017-11-09 23:32:55

标签: syslog rsyslog

我正在运行Ubuntu 16.04。我正在尝试使用rsyslogd来允许我将syslog消息发送到任何本地设施。这是我的配置:

dchappelle@L164:/etc/rsyslog.d$ cat 50-default.conf
#  Default rules for rsyslog.
#
#           For more information see rsyslog.conf(5) and /etc/rsyslog.conf

#
# First some standard log files.  Log by facility.
#
local0.*                /var/log/test-local-facility.log

auth,authpriv.*         /var/log/auth.log
*.*;auth,authpriv.none      -/var/log/syslog
#cron.*             /var/log/cron.log
#daemon.*           -/var/log/daemon.log
kern.*              -/var/log/kern.log
#lpr.*              -/var/log/lpr.log
mail.*              -/var/log/mail.log
#user.*             -/var/log/user.log

#
# Logging for the mail system.  Split it up so that
# it is easy to write scripts to parse these files.
#
#mail.info          -/var/log/mail.info
#mail.warn          -/var/log/mail.warn
mail.err            /var/log/mail.err

#
# Logging for INN news system.
#
news.crit           /var/log/news/news.crit
news.err            /var/log/news/news.err
news.notice         -/var/log/news/news.notice

#
# Some "catch-all" log files.
#
#*.=debug;\
#   auth,authpriv.none;\
#   news.none;mail.none -/var/log/debug
#*.=info;*.=notice;*.=warn;\
#   auth,authpriv.none;\
#   cron,daemon.none;\
#   mail,news.none      -/var/log/messages

#
# Emergencies are sent to everybody logged in.
#
*.emerg                                :omusrmsg:*

#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
#daemon,mail.*;\
#   news.=crit;news.=err;news.=notice;\
#   *.=debug;*.=info;\
#   *.=notice;*.=warn   /dev/tty8

# The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,
# you must invoke `xconsole' with the `-file' option:
#
#    $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
#      busy site..
#
daemon.*;mail.*;\
    news.err;\
    *.=debug;*.=info;\
    *.=notice;*.=warn   |/dev/xconsole
dchappelle@L164:/etc/rsyslog.d$

这是我的示例程序:

#include <stdio.h>
#include <unistd.h>
#include <syslog.h>

    int main(void)
    {
        openlog("test", LOG_PID|LOG_CONS, LOG_LOCAL0);
        syslog(LOG_INFO, "This is a test log message for local0");
        closelog();

        return 0;
    }

进行配置更改后,我重新启动了rsyslogd服务:

sudo service rsyslog restart

当我运行我的示例程序时,不会创建文件/var/log/test-local-facility.log。相反,syslog消息显示在/ var / log / syslog中。我已经搜索了互联网的内容,寻求帮助,没有这样的运气。我甚至尝试在调试模式下运行rsyslogd而没有骰子。那里有人有这方面的经验吗?

2 个答案:

答案 0 :(得分:0)

好的我手动创建了文件并更改了权限/所有者/组:

dchappelle@L164:/etc/rsyslog.d$ ls -l /var/log/test-local-facility.log
-rw-r----- 1 syslog adm 142 Nov  9 18:43 /var/log/test-local-facility.log

现在,当我运行示例程序时,日志消息按预期显示。但是,它仍然被发送到/ var / log / syslog,这不是我想要的。如何防止它被发送到那里?

答案 1 :(得分:0)

除了上述内容之外,为了使syslog消息不进入/ var / log / syslog,我还必须添加一条规则,以便在设施使用后停止处理:

local0.*                /var/log/test-local-facility.log
& stop

需要确保这是在任何其他设施规则之前。您会认为像这样的简单用例很容易找到示例。实际上,您会认为rsyslog文档会清楚地涵盖这个特定的用例。