Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

logging.config.fileConfig disables existing loggers

 
 
Robert
Guest
Posts: n/a
 
      08-30-2007
Hi

I have been grappling today with some unexpected behaviour from
logging.config.fileConfig.

I am using the following config file:
[loggers]
keys=root

[handlers]
keys=console

[formatters]
keys=form01

[logger_root]
level=DEBUG
handlers=console

[handler_console]
class=StreamHandler
level=NOTSET
formatter=form01
args=(sys.stdout,)

[formatter_form01]
format="%(asctime)s - %(name)s - %(filename)s:%(lineno)s - %
(levelname)s - %(message)s"
datefmt=

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?

Robert

--- config.py.old 2007-08-30 13:42:39.000000000 +0200
+++ config.py 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
configuration
+ 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:
log.addHandler(handlers[hand])

- #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 @@
else:
propagate = 1
logger = logging.getLogger(qn)
- if qn in existing:
- existing.remove(qn)
if "level" in opts:
level = cp.get(sectname, "level")
logger.setLevel(logging._levelNames[level])
@@ -227,12 +223,6 @@
for hand in hlist:
logger.addHandler(handlers[hand])

- #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
-

def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
"""

 
Reply With Quote
 
 
 
Reply

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



Advertisments