3

I am using multiprocessing with python 2.7. I would like each subprocess to log to its own file (filename = procname.pid.log) and NOT to the standarg log output. So far, I have been able to create each log file by creating a logger and FileHandler() in each subprocesses start() method, but I can't stop the log messages from also showing up in the parent log output. I understand that the parent environment is inherited, but how do I shut it off in the child processes?

My child processes are implemented as classes derived from multiprocessing.Process. I have avoided using logging.basicConfig, as I have heard it can only be executed once. I have seen this code suggested:

logger = logging.getLogger(__name__)
logger.propogate = False

But it has no effect.

I am not at all clear how the logging propogates up. I think that when I call getLogger, I have a new logger created called root.__module__, but I don't know how to get the root to stop printint to the screen.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
user1427057
  • 171
  • 1
  • 9
  • 1
    I am confused. I thought you can't log to the same file. http://stackoverflow.com/questions/10665090/logging-using-multiprocessing – CppLearner Nov 05 '13 at 19:39

1 Answers1

0

Is this on POSIX? Configure your logging after process creation. Then nothing should be inherited by the child processes from the parent process.

BTW note the correct spelling: propagate.

Also, see this post for more information.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191