Logpyles are full of snakes.
Features:
- Drop-in replacement for the python
logging
module - Turns uncaught exceptions into log entries
- Intelligently turns program output into log entries (for when you lack the energy to put in logging right away, or you are trying to tame a program not built with logging)
Future features:
- Provide useful hooks
- Support multiple processes
Logpyle came about so I could tame the output from a large pile of loosely associated python programs.
import logpyle
Do this in each python file you want to log.
To get more fancy, logpyle can replace python's logging
module:
import logpyle as logging
# Do whatever you normally do with the logging module
Global config is taken care of by writing a logpyle_config
module and putting it in your python path so that logpyle sees it when you are importing logpyle.
Here is an example logpyle_config.py
that redirects messages to the syslog:
import logging
from logging.handlers import SysLogHandler
syslog = SysLogHandler('/var/run/syslog', SysLogHandler.LOG_USER)
syslog.setFormatter(logging.Formatter('%(name)s %(levelname)s: %(message)s'))
HANDLERS = (syslog,)
LEVEL = logging.DEBUG
You can override the global configs by importing the logpyle_config
module and changing settings from the defaults:
import logpyle_config
logpyle_config.SUBVERT_IO = False
HANDLERS
-- A list of log handlers that you want to see the log events. Take a look at python'slogging.handlers
.LEVEL
(defaultlogging.DEBUG
) -- Global log level. Your handlers will accept events of this significance or higher.SUBVERT_EXCEPTHOOK
(defaultTrue
) -- Catch uncaught exceptions and logg them at thelogging.ERROR
levelSUBVERT_IO
(defaultTrue
) -- Log lines fromsys.stdout
andsys.stderr
STDOUT_LEVEL
(defaultlogging.INFO
) -- Log level forsys.stdout
STDERR_LEVEL
(defaultlogging.ERROR
) -- Log level forsys.stderr