Root logger sanity

Peter Otten __peter__ at web.de
Thu Mar 19 06:33:39 EDT 2015


Antoon Pardon wrote:

> On 03/19/2015 10:35 AM, martin.spamer at gmail.com wrote:
>> The following code is challenging my sanity, in my understanding of the
>> documentation this should pass, given that getLogger is supposed to
>> return the root logger and the root logger should be called 'root'.
> 
> Where do you get the idea that the root logger should be called 'root'?

>>> import logging
>>> logging.getLogger()
<logging.RootLogger object at 0x7fdef71a8630>
>>> _.name
'root'

The root logger is the only logger where

assert logger is logging.getLogger(logger.name)

fails. I can see that this may be a pitfall.

> AFAIU the documentation the root logger is nameless. So
> logging.getLogger() will return the root logger while
> logging.getLogger('root') will return the logger named 'root'
> 
> which are two different loggers.
> 
>>
>> https://docs.python.org/2/library/logging.html#logger-objects
>>
>> What am I missing?
>>
>>
>> from unittest import TestCase
>> import logging
>>
>> class LoggingSanityTest(TestCase):
>>
>>     def test_root_logging_sanity(self):
>>         assert logging.getLogger() == logging.getLogger('root')





More information about the Python-list mailing list