Jordi Boggiano 1 yıl önce
ebeveyn
işleme
d2d0341604

+ 6 - 4
src/Monolog/Handler/RotatingFileHandler.php

@@ -112,20 +112,22 @@ class RotatingFileHandler extends StreamHandler
      */
      */
     protected function write(array $record): void
     protected function write(array $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 ($this->mustRotate) {
-                $this->close(); // triggers rotation
-            }
         }
         }
 
 
+        // 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(); // triggers rotation
             $this->close(); // triggers rotation
         }
         }
 
 
         parent::write($record);
         parent::write($record);
+
+        if ($this->mustRotate) {
+            $this->close(); // triggers rotation
+        }
     }
     }
 
 
     /**
     /**