-# 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,
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!
"""
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):
"""
"""
Logger.__init__(self, "root", level)
+ def __reduce__(self):
+ return getLogger, ()
+
_loggerClass = Logger
class LoggerAdapter(object):
self.assertRaises(TypeError, logging.getLogger, any)
self.assertRaises(TypeError, logging.getLogger, b'foo')
+ def test_pickling(self):
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ for name in ('', 'root', 'foo', 'foo.bar', 'baz.bar'):
+ logger = logging.getLogger(name)
+ s = pickle.dumps(logger, proto)
+ unpickled = pickle.loads(s)
+ self.assertIs(unpickled, logger)
+
class BaseFileTest(BaseTest):
"Base class for handler tests that write log files"
Library
-------
+- bpo-30520: Loggers are now pickleable.
+
- bpo-30557: faulthandler now correctly filters and displays exception codes
on Windows
- bpo-30245: Fix possible overflow when organize struct.pack_into
error message. Patch by Yuan Liu.
-
+
- bpo-30378: Fix the problem that logging.handlers.SysLogHandler cannot
handle IPv6 addresses.