I am heavily using python threading, and my many use-cases require that I would log separate task executions under different logger names.
A typical code example would be:
def task(logger=logger):
global_logger.info('Task executing')
for item in [subtask(x) for x in range(100000)]:
# While debugging, one would generally prefer to see these
global_logger.debug('Task executed item {}'.format(item))
global_logger.info('Task done')
def thread_task(task_index, logger=logger):
task(logger=global_logger.getChild('main.task.{}'.format(task_index)))
def main():
pool = Pool(10)
for item in pool.map(thread_task, range(128))
pass
Is there any standard approach in python logging module that would allow me to set the logging level for all threads at once?
In code, what I am trying to do is:
# For all threads
logger.getChild('main.task.0').setLevel('INFO')
logger.getChild('main.task.1').setLevel('INFO')
logger.getChild('main.task.2').setLevel('INFO')
I should note that am aware that I could set the levels inside task_thread
. My question is there to find out if this can be done easier.