I have a problem using logging the library. I copied and modified the
example from PEP 282 [0], [1], [2], [3].
If I use logging.basicConfig() everything works fine. If I use
logging.config.fileConfig() my loggers get disabled. I checked logging/
config.py and I found a big comment saying that old loggers are
disabled! Why? What am I doing wrong? How do I use
logging.config.fileConfig() to avoid this problem ?
with logging.config.fileconfig()
--------------------
2009-04-10 17:49:19,955:MyApp:INFO - Starting my app
2009-04-10 17:49:19,955:MyApp:ERROR - There was a problem.
Traceback (most recent call last):
File "myapp.py", line 10, in <module>
mymodule.doIt()
File "/home/voodoo/src/mymodule.py", line 7, in doIt
raise TypeError, "Bogus type error for testing"
TypeError: Bogus type error for testing
2009-04-10 17:49:19,956:MyApp:INFO - Ending my app
----------------------
with logging.basicConfig()
----------------------
INFO:MyApp:Starting my app
DEBUG:MyModule:Doin' stuff...
ERROR:MyApp:There was a problem.
Traceback (most recent call last):
File "myapp.py", line 10, in <module>
mymodule.doIt()
File "/home/voodoo/src/mymodule.py", line 7, in doIt
raise TypeError, "Bogus type error for testing"
TypeError: Bogus type error for testing
INFO:MyApp:Ending my app
----------------------
[0] http://rafb.net/p/nl7b7m19.html
[1] http://rafb.net/p/n6KNdU44.html
[2] http://rafb.net/p/OxyTga98.html
[3] http://www.python.org/dev/peps/pep-0282/
This is by design, because fileConfig is not meant for incremental
configuration - it is for complete configuration of the logging
system. The old loggers which are not mentioned in the config file are
disabled (rather than removed from memory) as there might be threads
running which reference them. So if your logging configuration is
static for an application run you can use fileConfig. If it is
dyanmic, you are better off using programmatic configuration.
Regards,
Vinay Sajip