Skip to content

Commit d2d0341

Browse files
committed
Fix patch
1 parent d57089b commit d2d0341

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Monolog/Handler/RotatingFileHandler.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,22 @@ public function setFilenameFormat(string $filenameFormat, string $dateFormat): s
112112
*/
113113
protected function write(array $record): void
114114
{
115-
// on the first record written, if the log is new, we should rotate (once per day)
115+
// 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
116116
if (null === $this->mustRotate) {
117117
$this->mustRotate = null === $this->url || !file_exists($this->url);
118-
if ($this->mustRotate) {
119-
$this->close(); // triggers rotation
120-
}
121118
}
122119

120+
// if the next rotation is expired, then we rotate immediately
123121
if ($this->nextRotation <= $record['datetime']) {
124122
$this->mustRotate = true;
125123
$this->close(); // triggers rotation
126124
}
127125

128126
parent::write($record);
127+
128+
if ($this->mustRotate) {
129+
$this->close(); // triggers rotation
130+
}
129131
}
130132

131133
/**

0 commit comments

Comments
 (0)