mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-11 23:54:04 +02:00
Merge branch '2.x'
This commit is contained in:
@@ -71,10 +71,6 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
public function reset(): void
|
public function reset(): void
|
||||||
{
|
{
|
||||||
parent::reset();
|
parent::reset();
|
||||||
|
|
||||||
if (true === $this->mustRotate) {
|
|
||||||
$this->rotate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,17 +96,22 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
*/
|
*/
|
||||||
protected function write(LogRecord $record): void
|
protected function write(LogRecord $record): void
|
||||||
{
|
{
|
||||||
// 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 rotate (once per day) after the log has been written so that the new file exists
|
||||||
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 the next rotation is expired, then we rotate immediately
|
||||||
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);
|
||||||
|
|
||||||
|
if (true === $this->mustRotate) {
|
||||||
|
$this->close(); // triggers rotation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,6 +123,8 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
$this->url = $this->getTimedFilename();
|
$this->url = $this->getTimedFilename();
|
||||||
$this->nextRotation = $this->getNextRotation();
|
$this->nextRotation = $this->getNextRotation();
|
||||||
|
|
||||||
|
$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;
|
||||||
@@ -154,8 +157,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