I just started to use Python logging module and I cannot understand something.
I'm writing a script that works in the following way:
1st part (single process): it get some data to compute (it's not important how). Here I create a logger in the following way:
import logging
logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger('Pipeline')
logger.setLevel(logging.INFO)
logger.warning('Pipeline started')
In other words I log to the screen.
2nd part (multiprocessing): I create several processes (the data analysis is really time and CPU consuming) to analyze the data found before.
Now I would like that each process logs to a different file ONLY without logging to the screen.
What I wrote is :
fh = logging.FileHandler('/tmp/'+multiprocessing.current_process().name+'_worker.log')
fmt = logging.Formatter(%(asctime)-6s: %(name)s - %(levelname)s - %(message)s)
fh.setFormatter(fmt)
local_logger = logging.getLogger(multiprocessing.current_process().name+'_worker')
local_logger.addHandler(fh)
local_logger.warning(multiprocessing.current_process().name + ' (worker) Process started')
What I got is that each process logs to a different file but logs ALSO to the screen!
How can I fix this?