[GH-ISSUE #1905] $mustRotate in RotatingFileHandler not resetting properly #818

Closed
opened 2026-03-04 03:00:58 +03:00 by kerem · 0 comments
Owner

Originally created by @khoanguyen-3fc on GitHub (Aug 6, 2024).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1905

Our team is using Monolog version 2 and has encountered an issue where the $mustRotate attribute of the RotatingFileHandler is only set to false if all unrelated conditions in the rotate method are satisfied:

github.com/Seldaek/monolog@884aa47a05/src/Monolog/Handler/RotatingFileHandler.php (L128-L171)

This issue interacts with Octane, leading to a serious problem where logs cannot rotate to a new file. The problem arises because the reset method is called on every RequestReceived:

https://github.com/laravel/octane/blob/2.x/src/Listeners/FlushMonologState.php

When a RotatingFileHandler instance is reset with true === $this->mustRotate, the $this->url and $this->nextRotation attributes are updated by calling rotate:

github.com/Seldaek/monolog@884aa47a05/src/Monolog/Handler/RotatingFileHandler.php (L133-L135)

As a result, the write method cannot write to the new stream because $this->close() is never reached. This occurs because $this->nextRotation is already updated during the call to reset:

github.com/Seldaek/monolog@884aa47a05/src/Monolog/Handler/RotatingFileHandler.php (L113-L126)

Originally created by @khoanguyen-3fc on GitHub (Aug 6, 2024). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1905 Our team is using Monolog version 2 and has encountered an issue where the `$mustRotate` attribute of the `RotatingFileHandler` is only set to `false` if all unrelated conditions in the `rotate` method are satisfied: https://github.com/Seldaek/monolog/blob/884aa47a055ea3e8e351ceaf4dfc67f52fff44c0/src/Monolog/Handler/RotatingFileHandler.php#L128-L171 This issue interacts with Octane, leading to a serious problem where logs cannot rotate to a new file. The problem arises because the `reset` method is called on every `RequestReceived`: https://github.com/laravel/octane/blob/2.x/src/Listeners/FlushMonologState.php When a `RotatingFileHandler` instance is reset with `true === $this->mustRotate`, the `$this->url` and `$this->nextRotation` attributes are updated by calling `rotate`: https://github.com/Seldaek/monolog/blob/884aa47a055ea3e8e351ceaf4dfc67f52fff44c0/src/Monolog/Handler/RotatingFileHandler.php#L133-L135 As a result, the `write` method cannot write to the new stream because `$this->close()` is never reached. This occurs because `$this->nextRotation` is already updated during the call to `reset`: https://github.com/Seldaek/monolog/blob/884aa47a055ea3e8e351ceaf4dfc67f52fff44c0/src/Monolog/Handler/RotatingFileHandler.php#L113-L126
kerem 2026-03-04 03:00:58 +03:00
  • closed this issue
  • added the
    Bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#818
No description provided.