This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author llucax
Recipients llucax
Date 2008-06-19.01:01:49
SpamBayes Score 0.00017267712
Marked as misclassified No
Message-id <1213837323.33.0.0675974065144.issue3136@psf.upfronthosting.co.za>
In-reply-to
Content
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.
"""
History
Date User Action Args
2008-06-19 01:02:05llucaxsetspambayes_score: 0.000172677 -> 0.00017267712
recipients: + llucax
2008-06-19 01:02:03llucaxsetspambayes_score: 0.000172677 -> 0.000172677
messageid: <1213837323.33.0.0675974065144.issue3136@psf.upfronthosting.co.za>
2008-06-19 01:02:01llucaxlinkissue3136 messages
2008-06-19 01:01:56llucaxcreate