Enumerating loggers iin logging module

John Pote johnhpote at o2.co.uk
Sat Jan 3 17:54:33 EST 2015


Thanks for the replies, thought there'd be a simple answer. Much 
appreciated.
John

On 30/12/2014 22:40, Chris Angelico wrote:
> On Wed, Dec 31, 2014 at 8:24 AM, Tim Chase
> <python.list at tim.thechases.com> wrote:
>> While it may involve reaching into the objects may or may not be
>> blessed, the following seems to work for me in Py2.7:
>>
>>    >>> import logging
>>    >>> # add a bunch of loggers and sub-loggers
>>    >>> print logging.Logger.manager.loggerDict.keys()
> Works in 3.5, too, aside from trivialities:
>
> $ python3
> Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06)
> [GCC 4.7.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import logging
>>>> logging.getLogger("Name")
> <logging.Logger object at 0x7f8dcc339be0>
>>>> logging.getLogger("name.sublogger")
> <logging.Logger object at 0x7f8dcc339ba8>
>>>> logging.Logger.manager.loggerDict
> {'name.sublogger': <logging.Logger object at 0x7f8dcc339ba8>, 'Name':
> <logging.Logger object at 0x7f8dcc339be0>, 'name':
> <logging.PlaceHolder object at 0x7f8dcc33ebe0>}
>
> I'd say this is fine for debugging with.
>
> ChrisA




More information about the Python-list mailing list