shaunvxc / multiprocessing-logging

Handler for logging from multiple processes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

multiprocessing-logging

Downloads Supported Python versions Development Status Download format License

When using the multiprocessing module, logging becomes less useful since sub-processes should log to individual files/streams or there's the risk of records becoming garbled.

This simple module implements a Handler that when set on the root Logger will handle tunneling the records to the main process so that they are handled correctly.

Unfortunately, this technique only works with Processes and not with a Pool of processes. If you need this, I'd welcome a pull request! :)

It's currently tested in Linux and Python 2.7 and 3.4.

Origin

This library was taken verbatim from a StackOverflow post and extracted into a module so that I wouldn't have to copy the code in every project.

Usage

Before you start logging but after you configure the logging framework (maybe with logging.basicConfig(...)), do the following:

import multiprocessing_logging

multiprocessing_logging.install_mp_handler()

and that's it.

About

Handler for logging from multiple processes

License:GNU Lesser General Public License v3.0


Languages

Language:Python 100.0%