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
ec1cd1c4
Commit
ec1cd1c4
authored
Aug 30, 2010
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging: merged duplicated code in fileConfig and dictConfig paths.
parent
609364a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
18 deletions
+40
-18
Lib/logging/config.py
Lib/logging/config.py
+40
-18
No files found.
Lib/logging/config.py
View file @
ec1cd1c4
...
...
@@ -172,8 +172,28 @@ def _install_handlers(cp, formatters):
h
.
setTarget
(
handlers
[
t
])
return
handlers
def
_handle_existing_loggers
(
existing
,
child_loggers
,
disable_existing
):
"""
When (re)configuring logging, handle loggers which were in the previous
configuration but are not in the new configuration. There's no point
deleting them as other threads may continue to hold references to them;
and by disabling them, you stop them doing any logging.
However, don't disable children of named loggers, as that's probably not
what was intended by the user. Also, allow existing loggers to NOT be
disabled if disable_existing is false.
"""
root
=
logging
.
root
for
log
in
existing
:
logger
=
root
.
manager
.
loggerDict
[
log
]
if
log
in
child_loggers
:
logger
.
level
=
logging
.
NOTSET
logger
.
handlers
=
[]
logger
.
propagate
=
True
elif
disable_existing
:
logger
.
disabled
=
True
def
_install_loggers
(
cp
,
handlers
,
disable_existing
_loggers
):
def
_install_loggers
(
cp
,
handlers
,
disable_existing
):
"""Create and install loggers"""
# configure the root first
...
...
@@ -254,15 +274,15 @@ def _install_loggers(cp, handlers, disable_existing_loggers):
#and by disabling them, you stop them doing any logging.
#However, don't disable children of named loggers, as that's
#probably not what was intended by the user.
for
log
in
existing
:
logger
=
root
.
manager
.
loggerDict
[
log
]
if
log
in
child_loggers
:
logger
.
level
=
logging
.
NOTSET
logger
.
handlers
=
[]
logger
.
propagate
=
1
elif
disable_existing_loggers
:
logger
.
disabled
=
1
#
for log in existing:
#
logger = root.manager.loggerDict[log]
#
if log in child_loggers:
#
logger.level = logging.NOTSET
#
logger.handlers = []
#
logger.propagate = 1
#
elif disable_existing_loggers:
#
logger.disabled = 1
_handle_existing_loggers
(
existing
,
child_loggers
,
disable_existing
)
IDENTIFIER
=
re
.
compile
(
'^[a-z_][a-z0-9_]*$'
,
re
.
I
)
...
...
@@ -617,14 +637,16 @@ class DictConfigurator(BaseConfigurator):
#and by disabling them, you stop them doing any logging.
#However, don't disable children of named loggers, as that's
#probably not what was intended by the user.
for log in existing:
logger = root.manager.loggerDict[log]
if log in child_loggers:
logger.level = logging.NOTSET
logger.handlers = []
logger.propagate = True
elif disable_existing:
logger.disabled = True
#for log in existing:
# logger = root.manager.loggerDict[log]
# if log in child_loggers:
# logger.level = logging.NOTSET
# logger.handlers = []
# logger.propagate = True
# elif disable_existing:
# logger.disabled = True
_handle_existing_loggers(existing, child_loggers,
disable_existing)
# And finally, do the root logger
root = config.get('root', None)
...
...
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