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 <>
In-reply-to <>
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, (,)

> 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).
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