Best way to configure a logger hierarchy (was Re: A new way to configure Python logging)

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Oct 26 04:37:17 EDT 2009


Vinay Sajip wrote:
> Wolodja Wentland <wentland <at> cl.uni-heidelberg.de> writes:
>
>   
>> ----------------------
>>
>> I usually register a logger 'foo' within the application and one logger
>> for each module in the package, so the resulting logger hierarchy will
>> look like this:
>>
>>     foo
>>      |__bar
>>      |__baz
>>      |__newt
>>         |___witch
>>
>> I set every loggers log level to DEBUG and use the respective logger in
>>     
>
> You only need set foo's level to DEBUG and all of foo.bar, foo.baz etc.
> will inherit that level. Setting the level explicitly on each logger is
> not necessary, 

A little bit off topic, don't you just need to set the **root** logger 
debug level ?
I figured it out quite recently having problem configuring all my 
loggers with just one click:
I have an application importing modules, the application is not always 
aware of the logging support by the module. The only way to configure 
these modules loggers is by configuring the root logger.
If I'm not wrong, this mechanism should have been definitively  
described in the documentation within one the examples. The root logger 
being of little use (from user POV), it is easy to forget its existence. 
Actually it proved to me being very useful.

JM




More information about the Python-list mailing list