Package: epic-logging
Epic logging — Easy logging with multiprocessing supportWhat is it?Theepic-loggingPython library makes logging super easy. It is built on top of the builtinloggingframework, and provides two main functionalities:Easily create loggers that are named appropriately for their scope (function, class or module).Capture log records emitted from within a context, including from child processes, and redirect them
to a designated sink logger.ParadigmIt is important to separate any dependency between the emission and collection of log records.
The emitter should not be concerned with the formatting of the records, where they are going and who
will collect them, only with the log level. On the other hand, the collecting end should not be concerned with
where within the code the log records came from. It shouldknowwhere they came from, but should still
collect them, even if they were emitted from child processes, subpackages, etc.UsageGet a logger for your module, function or classTo get a logger for a module, useget_loggerin the module level:fromepic.loggingimportget_loggerlogger=get_logger()The logger name is automatically set to be the fully qualified module name.To get a logger for a function, useget_loggerinside the function:fromepic.loggingimportget_loggerdeffunc():logger=get_logger()The logger name is automatically set to be the fully qualified function name.To get a logger for a class, use theClassLoggerto create a class member:fromepic.loggingimportClassLoggerclassMyClass:logger=ClassLogger()Alternatively, use the ready-madeclass_loggerinstance:fromepic.loggingimportclass_loggerclassMyClass:logger=class_loggerThe class logger name is automatically set to be the full class name.Convenience pre-configured loggersTheepic.loggingpackage provides some convenient functions for getting pre-configured loggers for quick use.
These are meant to be used primarily when working interactively.Console loggerTo get a logger that emits to the console, useget_console_logger:fromepic.loggingimportget_console_loggerlogger=get_console_logger('LOGNAME')File loggerTo get a logger that emits to a file, useget_file_logger:fromepic.loggingimportget_file_loggerlogger=get_file_logger('LOGNAME','filename.log')Both console and fileTo get a logger that emits to both the console and a file, useget_file_and_console_logger:fromepic.loggingimportget_file_and_console_loggerlogger=get_file_and_console_logger('LOGNAME','filename.log')The Logregator — A logging aggregatorALogregatoris used for the aggregation of log records. It is initialized with a logger object
which acts as a sink—within the context of theLogregatorblock, all log records emitted above the sink's
log level are redirected to the sink logger. Crucially,this also works for log records emitted by sub-processes.
This makesLogregatorthe preferred way to collect log records, whether working interactively or in a
script. As the consumer, you don't care if functions or packages use multiprocessing internally or not,
you just want to get their log records. This is exactly whatLogregatordoes.UsingLogregatoris very simple. It is initialized with a sink logger, and used as a context manager:fromepic.loggingimportLogregator,get_console_loggerwithLogregator(get_console_logger('LOGNAME')):...# All logs here, even from sub-processes, are printed to the console.ConvenienceLogregatorinitializerFor the extremely common use cases of initializing aLogregatorover a logger which emits to the console
and/or a file, it is convenient to useLogtor, a subclass ofLogregator:fromepic.loggingimportLogtor# Emit to the consolewithLogtor():...# Emit to a filewithLogtor('filename.log'):...# Emit to both the console and a filewithLogtor('filename.log',console=True):...