Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87736 > unrolled thread

Root logger sanity

Started bymartin.spamer@gmail.com
First post2015-03-19 02:35 -0700
Last post2015-03-19 11:33 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Root logger sanity martin.spamer@gmail.com - 2015-03-19 02:35 -0700
    Re: Root logger sanity Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-03-19 11:09 +0100
    Re: Root logger sanity Peter Otten <__peter__@web.de> - 2015-03-19 11:33 +0100

#87736 — Root logger sanity

Frommartin.spamer@gmail.com
Date2015-03-19 02:35 -0700
SubjectRoot logger sanity
Message-ID<5277e05b-c333-4e25-80ba-bb9cd378ca84@googlegroups.com>
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'.  

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')

[toc] | [next] | [standalone]


#87738

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2015-03-19 11:09 +0100
Message-ID<mailman.23.1426759854.10327.python-list@python.org>
In reply to#87736
On 03/19/2015 10:35 AM, martin.spamer@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'?
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')

[toc] | [prev] | [next] | [standalone]


#87739

FromPeter Otten <__peter__@web.de>
Date2015-03-19 11:33 +0100
Message-ID<mailman.24.1426761236.10327.python-list@python.org>
In reply to#87736
Antoon Pardon wrote:

> On 03/19/2015 10:35 AM, martin.spamer@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')

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web