mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-26 08:05:53 +03:00
[GH-ISSUE #1016] GelfHandler::close() leaves the handler in a broken state. #416
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#416
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 @derula on GitHub (Jul 9, 2017).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1016
I commented on #614 because I was having the same problem, but my comment didn't get any visibility on a closed issue, so I'm hoping creating a new issue will help.
The gist is that in the destructor of Monolog\Handler\Handler, as well as in Monolog\ErrorHandler::handleFatalError(), ->close() is called on the handler. In case of GelfHandler, it unsets the publisher, leaving itself in a broken state.
If then some other code tries to log something, be it from a destructor that is randomly executed at a later time, or, in case of handleFatalError(), in another shutdown function, instead of gracefully refusing to log anything, the GelfHandler causes (another) fatal.
I agree that logging from shutdown functions or constructors may not be a good idea. However, I don't think the handler should cause a fatal error in these cases. For example, StreamHandler even re-opens the stream automatically in write() if it's been closed before. (I don't know whether that's a good idea, but that's what happens.)
Here is a short test script to show what I'm talking about:
Executing this will raise two fatal errors, first "something fatal," and then "Call to a member function publish() on null." For comparison, if you don't pass the handler to the Logger constructor, effectively creating a StreamHandler, only one fatal occurs (and afterwards the debug message is logged).
This can't be intended behavior...? Ideally, in my mind, every handler should act the same way and throw a specific exception if write() is called while it is closed. This exception could easily be caught and handled correctly. However, since for example the stream handler just gracefully re-opens its stream in that case, implementing this exception could be considered a BC break.