dynamically getting loggers

B

belred

is there a way to dynamically get all the active loggers?

i currently have code like this in different areas of the program:

import logging
log = logging.getLogger('foo')


i would like to write a function that dynamically get a list of all
the logger names such as 'foo'. or get a list of the loggers which i
could then get the names. is this even possible? i don't see a
logger function that returns loggers.

thanks,

bryan
 
G

Gabriel Genellina

is there a way to dynamically get all the active loggers?

i currently have code like this in different areas of the program:

import logging
log = logging.getLogger('foo')


i would like to write a function that dynamically get a list of all
the logger names such as 'foo'. or get a list of the loggers which i
could then get the names. is this even possible? i don't see a
logger function that returns loggers.

Loggers are created when requested, and I don't see a documented way to
get such list.
If you don't mind using undocumented attributes:

existing_logger_names = logging.getLogger().manager.loggerDict.keys()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top