Laravel选daily格式的日志,设置了days为什么没有按天删除旧的日志?

days设置了1,按理来说应该只保存1天的日志吧?

查看源码后发现

vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php
public function __construct(string $filename, int $maxFiles = 0, $level = Logger::DEBUG, bool $bubble = true, ?int $filePermission = null, bool $useLocking = false)
    {
        $this->filename = Utils::canonicalizePath($filename);
        $this->maxFiles = $maxFiles;
        $this->nextRotation = new \DateTimeImmutable('tomorrow');
        $this->filenameFormat = '{filename}-{date}';
        $this->dateFormat = static::FILE_PER_DAY;

        parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking);
    }

protected function write(array $record): void
    {
        // on the first record written, if the log is new, we should rotate (once per day)
        if (null === $this->mustRotate) {
            $this->mustRotate = null === $this->url || !file_exists($this->url);
        }
        if ($this->nextRotation <= $record['datetime']) {
            $this->mustRotate = true;
            $this->close();
        }

        parent::write($record);
    }

这里的$this->nextRotation是明天的时间,会永远小于$record['datetime']吧?
if ($this->nextRotation <= $record['datetime'])这个判断去掉才能正常删除旧文件。

是哪里的问题呢?

阅读 2.7k
1 个回答

daily 不是按天存储日志么,并不会删除历史日志

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题