rsyslog配置
rsyslog的配置文件為/etc/rsyslog.conf,但真正的配置放在/etc/rsyslog.d/目錄下
# Default rules for rsyslog.
#
# For more information see rsyslog.conf(5) and /etc/rsyslog.conf
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /var/log/auth.log
*.*;user.none;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 #設(shè)備類型.緊急程度
修改了rsyslog的配置文件后冯键,需要重啟服務(wù)來(lái)生效菲语,命令為service rsyslog restart
代碼示例
PHP代碼示例:
<?php
openlog('USER-LOG', LOG_PID, LOG_USER);
syslog(LOG_ERR, 'ERROR!!!');
closelog();
運(yùn)行結(jié)果:
$ cat /var/log/user.log
Mar 17 02:45:34 homestead USER-LOG[6540]: ERROR!!!
函數(shù)解釋
rsyslog會(huì)根據(jù)openlog()的設(shè)備類型妄辩,和syslog()的緊急程度,來(lái)確定該日志信息被寫入哪個(gè)文件
bool openlog ( string $ident , int $option , int $facility )
- $ident:日志的標(biāo)識(shí)山上,將被添加到日志信息中(USER-LOG)
- $option:示例中的值為L(zhǎng)OG_PID眼耀,因此pid進(jìn)程號(hào)將被添加到每條日志信息中([6540])
- $facility:該參數(shù)指定記錄信息的設(shè)備類型
bool syslog ( int $priority , string $message )
- 產(chǎn)生一條日志信息,并被rsyslog系統(tǒng)分發(fā)
- $priority:緊急程度