mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 20:27:31 +02:00
Fix RotatingFileHandler bug where rotation could sometimes not happen correctly, fixes #1905
This commit is contained in:
@@ -115,11 +115,14 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
// on the first record written, if the log is new, we should rotate (once per day)
|
// on the first record written, if the log is new, we should rotate (once per day)
|
||||||
if (null === $this->mustRotate) {
|
if (null === $this->mustRotate) {
|
||||||
$this->mustRotate = null === $this->url || !file_exists($this->url);
|
$this->mustRotate = null === $this->url || !file_exists($this->url);
|
||||||
|
if ($this->mustRotate) {
|
||||||
|
$this->close(); // triggers rotation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->nextRotation <= $record['datetime']) {
|
if ($this->nextRotation <= $record['datetime']) {
|
||||||
$this->mustRotate = true;
|
$this->mustRotate = true;
|
||||||
$this->close();
|
$this->close(); // triggers rotation
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::write($record);
|
parent::write($record);
|
||||||
@@ -134,6 +137,8 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
$this->url = $this->getTimedFilename();
|
$this->url = $this->getTimedFilename();
|
||||||
$this->nextRotation = new \DateTimeImmutable('tomorrow');
|
$this->nextRotation = new \DateTimeImmutable('tomorrow');
|
||||||
|
|
||||||
|
$this->mustRotate = false;
|
||||||
|
|
||||||
// skip GC of old logs if files are unlimited
|
// skip GC of old logs if files are unlimited
|
||||||
if (0 === $this->maxFiles) {
|
if (0 === $this->maxFiles) {
|
||||||
return;
|
return;
|
||||||
@@ -166,8 +171,6 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mustRotate = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTimedFilename(): string
|
protected function getTimedFilename(): string
|
||||||
|
Reference in New Issue
Block a user