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.
"""

The problem is you can't always do that call before using the loggers.
In my case, I get the logging config file via command-line arguments
(using optparse), but before I can't even know what logging config file
to load, I have log calls.
Please reopen the bug, the actual solution is not flexible enough.