rsyslog学习2 -- sysklogd 格式

sysklogd 格式

​ 这个使用syslog来说明,rsyslog也使用同样的格式

说明

​ 在 *nix 系统上,syslogd(8)的配置文件为 syslog.conf

​ 每一条规则分为 selector 和 action 两部分,由一个以上的空格或tab分割

​ 用为注释,\ 用来合并多选

SELECTORS

​ selector 可分为 facility 和 priority 两部分,用 “.” 分割,区分大小写,也可以用 /usr/include/syslog.h 中定义的数字来表示。

​ facility 用来表示产生日志的子系统,可分为 auth, authpriv, cron, daemon, ftp, kern, lpr, mail, mark, news, security (same as auth,已废弃), syslog, user, uucp and local0 through local7 。任何人都可以发送消息到除了 kern 的任何 facility 。

​ priority 从低到高分为 debug, info, notice, warning, warn (same as warning,已废弃), err, error (same as err,已废弃), crit, alert, emerg, panic (same as emerg,已废弃)。

​ 默认当消息priority等于或高于配置的级别时,syslogd会动作。也可以使用 “=” 来只指定某一级别。

​ facility 和 priority 可以用 “*” 来代表所有。none 代表不匹配任何项。

​ 可以同时使用多个 facility,用”,”分割,但同时只能对应一个 priority 。

​ 可以同时使用多个 selectors 来对应一个action,使用”;”分割,执行顺序为从左到右,后者会覆盖前者,可用来作某些 exclude的操作。

​ 可以在 priority 前加 “!” 表示忽略等于或大于该级别的消息,可以和 “=” 一直使用。

ACTIONS

Regular File

​ 记录到文件,可以使用相对路径,但非常不建议这么做。

Named Pipes

​ 可以发送到 named pipes (fifos),一般用来debug,需要使用 mkfifo 命令先创建 fifo 设备。

Terminal and Console

​ 可以发送到 /dev/console 或 tty。

1
2
3
4
# The tcp wrapper logs with mail.info, we display
# all the connections on tty12
#
mail.=info /dev/tty12

Remote Machine

​ 可以从远程接受消息,或发送到远端机器。远程默认不会再转发消息。如果要发送消息到远端,格式为 @remote_hostname

​ 作为接受者,可以使用 named pipe 处理接受到消息。

1
*.*       @finlandia

List of Users

​ 通常,critical 消息会发送给本机root,也可以配置多个 user 接受消息,使用”,”分割,如果这些user在线的话,将会在terminal上收到消息。

1
2
3
4
# Messages of the priority alert will be directed
# to the operator
#
*.alert root,joey

Everyone logged on

​ 一些紧急的消息会发送给所有在线用户,使用 “*” 来启用这个功能。

1
2
3
# Emergency messages will be displayed using wall
#
*.=emerg *

例子

1
2
3
# Store critical stuff in critical
#
*.=crit;kern.none /var/adm/critical

发送crit 到 /var/adm/critical,除了 kern的消息。

1
2
3
4
5
6
7
8
# Kernel messages are stored in the kernel file,
# critical messages and higher ones also go
# to another host and to the console
#
kern.* /var/adm/kernel
kern.crit @finlandia
kern.crit /dev/console
kern.info;kern.!err /var/adm/kernel-info

第四行,发磅kern的info以上的消息,除了err

1
2
3
# Write all mail related logs to a file
#
mail.*;mail.!=info /var/adm/mail
1
2
3
# Log all mail.info and news.info messages to info
#
mail,news.=info /var/adm/info

匹配来自mail和news的info消息

1
2
3
4
# Log info and notice messages to messages file
#
*.=info;*.=notice;\
mail.none /var/log/messages
1
2
3
4
# Log info messages to messages file
#
*.=info;\
mail,news.none /var/log/messages
0%