如何使用PHP日志配置logrotate [英] How to configure logrotate with php logs

查看:187
本文介绍了如何使用PHP日志配置logrotate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用APC运行php5 FPM作为操作码和应用程​​序缓存.和往常一样,我正在将php错误记录到文件中.

I'm running php5 FPM with APC as an opcode and application cache. As is usual, I am logging php errors into a file.

由于它变得很大,因此我尝试配置logrotate.它可以工作,但是轮换后,php仍会继续登录到现有的日志文件,即使重命名也是如此.这导致scripts.log为0B文件,而scripts.log.1继续增长.

Since that is becoming quite large, I tried to configure logrotate. It works, but after rotation, php continues to log to the existing logfile, even when it is renamed. This results in scripts.log being a 0B file, and scripts.log.1 continuing to grow further.

我认为(尚未尝试过)在postrotate中运行php5-fpm reload可以解决此问题,但这每次都会清除我的APC缓存.

I think (haven't tried) that running php5-fpm reload in postrotate could resolve this, but that would clear my APC cache each time.

有人知道如何使它正常工作吗?

Does anybody know how to get this working properly?

推荐答案

我发现用于logrotate的"copytruncate"选项可确保inode不变.基本上[sic!]一直在寻找什么.

I found that "copytruncate" option to logrotate ensures that the inode doesn't change. Basically what is [sic!] was looking for.

这可能是您要寻找的.摘自: logrotate如何工作? -Linuxquestions.org .

This is probably what you're looking for. Taken from: How does logrotate work? - Linuxquestions.org.

正如我的评论所写,您需要防止PHP写入同一文件(重命名).复制文件通常会创建一个新文件,而截断也是该选项名称的一部分,因此我认为 copytruncate 选项是一个简单的解决方案(

As written in my comment, you need to prevent PHP from writing into the same (renamed) file. Copying a file normally creates a new one, and the truncating is as well part of that options' name, so I would assume, the copytruncate option is an easy solution (from the manpage):

  copytruncate

          Truncate  the  original log file in place after creating a copy,
          instead of moving the old log file and optionally creating a new
          one,  It  can be used when some program can not be told to close
          its logfile and thus might continue writing (appending)  to  the
          previous log file forever.  Note that there is a very small time
          slice between copying the file and truncating it, so  some  log-
          ging  data  might be lost.  When this option is used, the create
          option will have no effect, as the old log file stays in  place.

另请参见:

这篇关于如何使用PHP日志配置logrotate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆