当前位置:首页 > 操作系统 > Linux

linux – syslog在日志轮换后停止记录

每次newsyslog旋转日志文件后,syslog都会停止登录该文件.直到syslogd重启完成.

(myserver:wheel)# logger -p local1.info -t myprocess "hello thiru"; ll myfile.log; cat myfile.log
-rw-r--r--  1 root  wheel     0B Nov 10 11:26 myfile.log

(myserver:wheel)# /etc/rc.d/syslogd restart
Stopping syslogd.
Starting syslogd.

(myserver:wheel)# logger -p local1.info -t myprocess "hello thiru"; ll myfile.log; cat myfile.log
-rw-r--r--  1 root  wheel    44B Nov 10 12:04 myfile.log
Nov 10 12:04:31 myserver myprocess: hello thiru 
(myserver:wheel)#

在Linux(使用logrotate)上,我们可以通过在logroate conf的postrotate部分中执行syslog / rsyslog重新启动来解决此问题.

在newsyslog中有类似于postrotate的东西吗?

编辑:

Syslog和newsyslog conf文件:

(TPC-E11-36:wheel)# cat /etc/newsyslog.d/newsyslog-myprocess.conf
/var/log/myfile.log 644 20 10000 * Z

(TPC-E11-36:wheel)# cat /etc/syslog.d/syslog-myprocess.conf
!myprocess
local1.info /var/log/myfile.log
(TPC-E11-36:wheel)#

解决方法:

将pidfile的路径添加到/etc/newsyslog.conf中,如果需要,还有一个代表SIGHUP的信号,有关newsyslog的更多信息:https://www.freebsd.org/doc/handbook/configtuning-syslog.html

格式/示例是这样的:

# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]

/var/log/your-app.log   root:wheel      600  7     *    @T00  GBJC  /var/run/your-app.pid 1

另见这个答案:https://serverfault.com/a/701563/94862


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!