Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > logging.config.fileConfig disables existing loggers

Thread Tools

logging.config.fileConfig disables existing loggers

Posts: n/a

I have been grappling today with some unexpected behaviour from

I am using the following config file:





format="%(asctime)s - %(name)s - %(filename)s:%(lineno)s - %
(levelname)s - %(message)s"

As you can see, it sets the root logger level to be DEBUG. I would
expect this to have the same effect as calling logger.basicConfig with
a level = DEBUG. What instead happens is that all my loggers become
disabled. One might argue that the loggers should only be created
after configuring the logger, but what about using the listening
method to configure again later...

While I can understand that the application of a new config file is
not incremental, ie should override any previous configuration
completely, it does not appear right that only loggers explicitly
named in the config file are enabled. I would expect that if I enabled
a particular logger then all child loggers should be enabled too.
Alternatively one needs to know the names of all loggers a-priori in
order to be able to monitor them.

So I took the liberty to try to discern what is going on. The culprit
(from my perspective) was the logging.config._install_loggers method,
particularly the last two lines which disable any logger not mentioned
in the config file. If those lines are deleted and a new loop is
created at the top of the function which resets all existing loggers
to their default status, then we see the desired behaviour. This seems
quite simple and sensible. Below is a patch file for applying the
change. What do people think?


--- 2007-08-30 13:42:39.000000000 +0200
+++ 2007-08-30 13:53:15.000000000 +0200
@@ -173,6 +173,14 @@
def _install_loggers(cp, handlers):
"""Create and install loggers"""

+ # reset all existing loggers so that they can inherit new
+ for log in logging.root.manager.loggerDict.keys():
+ logger = logging.root.manager.loggerDict[log]
+ logger.level = logging.NOTSET
+ logger.propagate = 1
+ logger.handlers = []
+ logger.disabled = 0
# configure the root first
llist = cp.get("loggers", "keys")
llist = string.split(llist, ",")
@@ -192,16 +200,6 @@
for hand in hlist:

- #and now the others...
- #we don't want to lose the existing loggers,
- #since other threads may have pointers to them.
- #existing is set to contain all existing loggers,
- #and as we go through the new configuration we
- #remove any which are configured. At the end,
- #what's left in existing is the set of loggers
- #which were in the previous configuration but
- #which are not in the new configuration.
- existing = root.manager.loggerDict.keys()
#now set up the new ones...
for log in llist:
sectname = "logger_%s" % log
@@ -212,8 +210,6 @@
propagate = 1
logger = logging.getLogger(qn)
- if qn in existing:
- existing.remove(qn)
if "level" in opts:
level = cp.get(sectname, "level")
@@ -227,12 +223,6 @@
for hand in hlist:

- #Disable any old loggers. There's no point deleting
- #them as other threads may continue to hold references
- #and by disabling them, you stop them doing any logging.
- for log in existing:
- root.manager.loggerDict[log].disabled = 1


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Question about Loggers, Parent Loggers, and Levels Rhino Java 8 04-30-2010 10:20 PM
OnClientClick 'return' disables validation Florian Doyon ASP .Net 0 09-15-2005 02:43 PM
Wireless card disables existing adapters in W2K ? Amamba Wireless Networking 0 09-08-2005 01:15 AM
PreRender Disables the User controls events =?Utf-8?B?Sm9obiBOaW5hbg==?= ASP .Net 1 09-24-2004 04:33 PM
Smartnavigation disables ActiveX Events (OWC) Kevin Ortman ASP .Net 0 12-05-2003 04:28 AM