This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients pitrou, vinay.sajip
Date 2017-06-01.07:18:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <ef2d3142-2b62-2dd0-e8ef-ccd0f0fd3bfe@free.fr>
In-reply-to <1496301247.13.0.287758895999.issue30520@psf.upfronthosting.co.za>
Content
Le 01/06/2017 à 09:14, Vinay Sajip a écrit :
> 
> I am not sure it is a good idea to support pickling of loggers, as they are singletons and generally aren't supposed to be instantiated other than by calling logging.getLogger(name).

Pickling them by name is precisely what I'm having in mind.  Right now,
pickle tries to recreate them structurally, which fails.

In other words (untested, but you get the idea):

  class Logger:
      def __reduce__(self):
          return getLogger, (self.name,)

> What's the use case for pickling them,

You usually don't pickle loggers directly.  You pickle an object that
happens to hold (directly or indirectly) a reference to a logger (it's
quite common to have `self.logger = ...` in your code), and pickle tries
to pickle the logger as part of pickling that object.

> One could implement __getstate__() to just return the name, but there
is no corresponding obvious implementation of __setstate__() because
loggers aren't meant to be instantiated via unpickling.

No need for __getstate__ or __setstate__, __reduce__ should work fine
(see above).
History
Date User Action Args
2017-06-01 07:18:31pitrousetrecipients: + pitrou, vinay.sajip
2017-06-01 07:18:31pitroulinkissue30520 messages
2017-06-01 07:18:30pitroucreate