mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-27 08:35:53 +03:00
[GH-ISSUE #794] RotatingFileHandler fails to call rotate() when used in a short-lived process #303
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#303
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mberkowski on GitHub (May 23, 2016).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/794
When integrating Monolog into a Drupal site on Apache/mod_php, we found that RotatingFileHandler fails to call
rotate()in its GC routine. New date-stamped logfiles are created, but old ones never disposed. This seems due to the fact thatRotatingFileHandler::$nextRotationis initialized to tomorrow's date, and later compared less than the logged item's date stamp.In a short-lived process like an HTTP request under mod_php the initialized
nextRotationwill always be greater than the logged item's timestamp preventingRotatingFileHandler::close()and consequentlyRotatingFileHandler::rotate()from being called when depending on this implicit call toclose().In
RotatingFileHandlerTest::testRotation(), an explicit call is made to$handler->close()causing the garbage collection to take place and test to pass. An explicit call toRotatingFileHandler::close()is therefore a possible workaround.github.com/Seldaek/monolog@6d2cfa63c9/src/Monolog/Handler/RotatingFileHandler.php (L47-L53)github.com/Seldaek/monolog@6d2cfa63c9/src/Monolog/Handler/RotatingFileHandler.php (L100-L103)@Seldaek commented on GitHub (May 26, 2016):
Normally all handler's close method is called by __destruct, so I am not sure why you don't get a rotation triggered?
@mberkowski commented on GitHub (May 26, 2016):
Yes, I see that way up in
Monolog\Handler\Handler::__destruct(). My guess is that since it's inside Drupal, any number of things could be interfering with normal shutdown & GC to prevent__destruct()executing. I find that if I comment out the explicitclose()in the test but still explicitlyunset($handler)the test passes because__destruct()cleans up. So Monolog is probably working as intended.@Seldaek commented on GitHub (May 26, 2016):
Yup I am pretty sure this works, but I'm quite curious to see what interferes with that in Drupal..
@mberkowski commented on GitHub (May 27, 2016):
This turned out to be due to a strange set of local circumstances and a faulty directory ACL I might have discovered sooner had I noticed the base class
__destruct()callingclose(). Apologies for the noise.@attisan commented on GitHub (Nov 8, 2018):
sorry for excavating this issue, but I'm experiencing a very similar behaviour with monolog and drupal 8 using RotatingFileHandler. Although
close()gets called,$this->mustRotateis eitherNULLorFALSEfor the same reasons as @mberkowski described.As a result the check
if (true === $this->mustRotate) {inclose()gates off$this->rotate();.