rsyslog和在PHP上的应用

2017-04-07  本文已影响0人  Uchiha_Ponny

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        #设备类型.紧急程度

修改了rsyslog的配置文件后,需要重启服务来生效,命令为service rsyslog restart

代码示例

PHP代码示例:

<?php

openlog('USER-LOG', LOG_PID, LOG_USER);
syslog(LOG_ERR, 'ERROR!!!');
closelog();

运行结果:

$ cat /var/log/user.log

Mar 17 02:45:34 homestead USER-LOG[6540]: ERROR!!!

函数解释

rsyslog会根据openlog()的设备类型,和syslog()的紧急程度,来确定该日志信息被写入哪个文件

bool openlog ( string $ident , int $option , int $facility )

$option $facility

bool syslog ( int $priority , string $message )

$priority
上一篇下一篇

猜你喜欢

热点阅读