mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-26 08:05:53 +03:00
[GH-ISSUE #365] Make handlers serializable #125
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#125
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 @deceze on GitHub (May 12, 2014).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/365
It would be really helpful if handlers would be serializable by default. I'm often injecting loggers as dependencies into objects, and then may cache those objects. Upon retrieving the objects from cache, the logger is typically broken because its resources of course fail serialization/unserialization (e.g. the default
StreamHandler).The fix is easy, in the case of
StreamHandlerthis is all that's needed:Rather hacky, but that's all that's required; the rest of the class is already behaving as needed.
Please consider adding proper
__sleep/__wakeupcompatibility to all handlers by default.@staabm commented on GitHub (May 12, 2014):
wouldn't it be more apropriate that you exclude the field from serialization and create a new instance after wakeup?
having the stream handler itself serializable doesn't make sense IMO.
@deceze commented on GitHub (May 12, 2014):
That means I'd have to force the object itself to worry about instantiating and configuring a logger, when right now I'm simply requiring a
LoggerInterfacein its constructor. I don't want my objects to have to worry about instantiating and configuring a dependency they currently simply receive; I also don't want to have to do this for every single one of my cacheable objects when the solution can neatly be implemented in the logger itself.@stof commented on GitHub (May 12, 2014):
@deceze forcing handlers to be serializable is a bad idea IMO, because it restricts too much what can be used to implement it (they can only depend on serializable services).
Thus, if you serialize 2 cacheable objects and unserialize them, you will get 2 new logger instances (with their own file handles open on the same file, which is likely to cause some weird issues).
you should better rethink the way you handle caching (data object should be what you cache, not services, while logging is more expected to be used in service objects)
@Seldaek commented on GitHub (May 19, 2014):
I agree that we can't force every handler to be serializable if it's not possible reasonably, for example a stream handler that receives an open stream can not possibly reopen it after wakeup. But I'm fine with adding support for serialization where it's harmless, if you like to send a PR that'd be great.
@deceze commented on GitHub (May 19, 2014):
Sounds good, I'll look into it when I have a moment. Loggers which can't be serialised should probably complain when somebody attempts to serialise them as well.