[issue3136] [PATCH] logging.config.fileConfig() compulsivly disable all existing loggers

Leandro Lucarella report at bugs.python.org
Thu Jun 19 03:02:04 CEST 2008


New submission from Leandro Lucarella <llucax at gmail.com>:

When using logging.config.fileConfig() in a large project, with several
nested loggers, is very counterintuitive and annoying that this function
disable all non-configured-via-fileConfig() loggers, because it forces
the config file to configure *all* the loggers there, which makes the
file unmaintainable, and throws the beauty of hierarchical loggers to
the trash.

Attached is a sample patch that adds a new option
"disable_existing_loggers" to fileConfig() function (defaulting to True,
to make it backward-compatible) to control this behavior. If you like
the idea I can update the documentation and add some testcases too.

You can see a simple example about the problem and solution here:
log.py:  http://pastebin.lugmen.org.ar/4204
log.ini: http://pastebin.lugmen.org.ar/4205

without the patch, the output is:
logger:DEBUG: log debug
logger:INFO: log info
logger:WARNING: log warning
logger:ERROR: log error
logger:CRITICAL: log critical

With the patch (and passing disable_existing_loggers=False to
fileConfig()) yields this output:
logger:DEBUG: log debug
logger:INFO: log info
logger:WARNING: log warning
logger:ERROR: log error
logger:CRITICAL: log critical
logger.sublogger:DEBUG: sublog debug
logger.sublogger:INFO: sublog info
logger.sublogger:WARNING: sublog warning
logger.sublogger:ERROR: sublog error
logger.sublogger:CRITICAL: sublog critical

As one could expect when reading the logging module docs:
"""
getLogger() returns a reference to a logger instance with the specified
if it it is provided, or root if not. The names are period-separated
hierarchical structures. Multiple calls to getLogger() with the same
name will return a reference to the same logger object. Loggers that are
further down in the hierarchical list are children of loggers higher up
in the list. For example, given a logger with a name of foo, loggers
with names of foo.bar, foo.bar.baz, and foo.bam are all children of foo.
Child loggers propagate messages up to their parent loggers. Because of
this, it is unnecessary to define and configure all the loggers an
application uses. It is sufficient to configure a top-level logger and
create child loggers as needed.
"""

----------
components: Library (Lib)
files: logging.config.disable_existing_loggers.patch
keywords: patch
messages: 68388
nosy: llucax
severity: normal
status: open
title: [PATCH] logging.config.fileConfig() compulsivly disable all existing loggers
versions: Python 2.5
Added file: http://bugs.python.org/file10657/logging.config.disable_existing_loggers.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3136>
_______________________________________


More information about the Python-bugs-list mailing list