http://areyouok.iteye.com/blog/287980
簡介
不同的Linux發行版使用不同syslog程序來記錄系統日志。
的Debain 4.0/Ubuntu8.04(桌面版)默認使用的是sysklogd,配置文件為/etc/syslog.conf。
Fedora9默認使用rsyslogd,配置文件為/etc/rsyslog.conf。
opensuse11使用syslog-ng,配置文件為/etc/syslog-ng/syslog-ng.conf。
這里僅一debian為例介紹一下syslog.conf的配置,rsyslog.conf的格式和syslog.conf是基本一樣的。可以用man syslog.conf命令查看配置幫助。
配置文件由多條規則構成,每條規則有3個部分,#開頭的是注釋。每條規則分3個部分指定Facility、Severity以及要采取的措施。規則是組合 的。
例子
下面的規則指定Facility為mail,Severity為err以上級別的日志寫入/var/log/mail.err文件,而err以下級別的日 志則被忽略:
mail.err /var/log/mail.err
Facility和Severity可以使用通配符,也可以指定多個,用逗號隔開:
auth,authpriv.* /var/log/auth.log
Facility和Severity的組合可以有多個,用分號隔開,文件前面加一個減號表示日志不立即寫入文件,而是在緩沖中積攢到一定的條件再寫,這樣 可以提高性能,但是當機可能會丟失數據:
*.*;auth,authpriv.none -/var/log/syslog
可以把syslog消息通過UDP發送到syslog服務器的514端口:
*.err @192.168.0.1
發生錯誤時,在控制台打屏:
*.err /dev/console
日志格式
debian 4.0外發的syslog都有換行符\n結尾,沒有主機名和時間,例如:
<38>su[2257]: (pam_unix) session opened for user root by root(uid=0)
<30>dhclient: bound to 192.168.233.129 -- renewal in 878 seconds.
本地syslog日志文件中的樣本(/var/log/auth.log),有主機名和時間,但沒有Facility和Severity
Oct 8 22:36:56 debian sshd[2261]: (pam_unix) session opened for user root by root(uid=0)
fedora的rsyslogd轉發的syslog則沒有換行符\n結尾。
最后給出debian4.0默認的syslog.conf文件 :
# /etc/syslog.conf Configuration file for syslogd.
#
# For more information see syslog.conf(5)
# manpage.
#
# First some standard logfiles. Log by facility.
#
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
uucp.* /var/log/uucp.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' logfiles.
#
*.=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 *
#
# 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.crit;news.err;news.notice;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole