diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2017-06-06 15:34:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-06 15:34:29 (GMT) |
commit | 6260d9f2039976372e0896d517b3c06e606eb169 (patch) | |
tree | 5222777b12a41ead8367261d1c80c22eefca012d /Lib/logging | |
parent | b87c0dfe902009e926edfb4ea5c7b26dcbdca2fe (diff) | |
download | cpython-6260d9f2039976372e0896d517b3c06e606eb169.zip cpython-6260d9f2039976372e0896d517b3c06e606eb169.tar.gz cpython-6260d9f2039976372e0896d517b3c06e606eb169.tar.bz2 |
bpo-30520: Implemented pickling for loggers. (#1956)
Implemented pickling for loggers.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 4920383..64e24ee 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2001-2016 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2017 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -18,7 +18,7 @@ Logging package for Python. Based on PEP 282 and comments thereto in comp.lang.python. -Copyright (C) 2001-2016 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2017 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! """ @@ -1570,6 +1570,14 @@ class Logger(Filterer): level = getLevelName(self.getEffectiveLevel()) return '<%s %s (%s)>' % (self.__class__.__name__, self.name, level) + def __reduce__(self): + # In general, only the root logger will not be accessible via its name. + # However, the root logger's class has its own __reduce__ method. + if getLogger(self.name) is not self: + import pickle + raise pickle.PicklingError('logger cannot be pickled') + return getLogger, (self.name,) + class RootLogger(Logger): """ @@ -1583,6 +1591,9 @@ class RootLogger(Logger): """ Logger.__init__(self, "root", level) + def __reduce__(self): + return getLogger, () + _loggerClass = Logger class LoggerAdapter(object): |