Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Nov 11, 2024
2 parents 0c73661 + d2d0341 commit 7729f32
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Monolog/Handler/RotatingFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ public function close(): void
public function reset(): void
{
parent::reset();

if (true === $this->mustRotate) {
$this->rotate();
}
}

/**
Expand All @@ -100,17 +96,22 @@ public function setFilenameFormat(string $filenameFormat, string $dateFormat): s
*/
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) {
$this->mustRotate = null === $this->url || !file_exists($this->url);
}

// if the next rotation is expired, then we rotate immediately
if ($this->nextRotation <= $record->datetime) {
$this->mustRotate = true;
$this->close();
$this->close(); // triggers rotation
}

parent::write($record);

if (true === $this->mustRotate) {
$this->close(); // triggers rotation
}
}

/**
Expand All @@ -122,6 +123,8 @@ protected function rotate(): void
$this->url = $this->getTimedFilename();
$this->nextRotation = $this->getNextRotation();

$this->mustRotate = false;

// skip GC of old logs if files are unlimited
if (0 === $this->maxFiles) {
return;
Expand Down Expand Up @@ -154,8 +157,6 @@ protected function rotate(): void
restore_error_handler();
}
}

$this->mustRotate = false;
}

protected function getTimedFilename(): string
Expand Down

0 comments on commit 7729f32

Please sign in to comment.