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'])
这个判断去掉才能正常删除旧文件。
是哪里的问题呢?
daily
不是按天存储日志么,并不会删除历史日志