Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6260d9f2
Commit
6260d9f2
authored
Jun 06, 2017
by
Vinay Sajip
Committed by
GitHub
Jun 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30520: Implemented pickling for loggers. (#1956)
Implemented pickling for loggers.
parent
b87c0dfe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
3 deletions
+26
-3
Doc/library/logging.rst
Doc/library/logging.rst
+2
-0
Lib/logging/__init__.py
Lib/logging/__init__.py
+13
-2
Lib/test/test_logging.py
Lib/test/test_logging.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-1
No files found.
Doc/library/logging.rst
View file @
6260d9f2
...
...
@@ -323,6 +323,8 @@ is the module's name in the Python package namespace.
..
versionadded
::
3.2
..
versionchanged
::
3.7
Loggers
can
now
be
picked
and
unpickled
.
..
_levels
:
...
...
Lib/logging/__init__.py
View file @
6260d9f2
# Copyright 2001-201
6
by Vinay Sajip. All Rights Reserved.
# Copyright 2001-201
7
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-201
6
Vinay Sajip. All Rights Reserved.
Copyright (C) 2001-201
7
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
):
...
...
Lib/test/test_logging.py
View file @
6260d9f2
...
...
@@ -4086,6 +4086,14 @@ class LoggerTest(BaseTest):
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
"
...
...
Misc/NEWS
View file @
6260d9f2
...
...
@@ -345,6 +345,8 @@ Extension Modules
Library
-------
- bpo-30520: Loggers are now pickleable.
- bpo-30557: faulthandler now correctly filters and displays exception codes
on Windows
...
...
@@ -353,7 +355,7 @@ Library
- 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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment