polymerist.genutils.logutils.IOHandlers

Tools for simplifying logging from multiple sources

Attributes

LOG_FORMATTER

MSFHandler

MSFHandlerFlex

Classes

MultiStreamFileHandler

Class to simplify logging file I/O given multiple logger sources providing logging input

MultiStreamFileHandlerFlexible

MSFHandler which is a bit more flexible (and lazy) when it comes to log file naming and creation

Functions

get_logger_registry(→ dict[str, logging.Logger])

Gets all registered Loggers by module

get_active_loggers(→ list[logging.Logger])

submodule_loggers(→ dict[str, Optional[logging.Logger]])

Produce a dict of any Logger objects present in each submodule. Can optionally generate recursively and blacklist certain modules

Module Contents

polymerist.genutils.logutils.IOHandlers.LOG_FORMATTER
polymerist.genutils.logutils.IOHandlers.get_logger_registry() dict[str, logging.Logger][source]

Gets all registered Loggers by module

polymerist.genutils.logutils.IOHandlers.get_active_loggers() list[logging.Logger][source]
polymerist.genutils.logutils.IOHandlers.submodule_loggers(module: types.ModuleType, recursive: bool = True, blacklist: Iterable[str] | None = None, sparse: bool = True) dict[str, logging.Logger | None][source]

Produce a dict of any Logger objects present in each submodule. Can optionally generate recursively and blacklist certain modules

Parameters:
  • module (ModuleType) – The “root” module to begin importing from Represented in the Node object returned by this function

  • recursive (bool, default=True) – Whether or not to recursively import modules from subpackages and add them to the tree

  • blacklist (list[str] (optional), default None) – List of module names to exclude from tree building If provided, will exclude any modules whose names occur in this list

  • sparse (bool, default=True) – Whether to only include modules which have a Logger defined (i.e. exclude all NoneType entries from returned dict)

Returns:

logger_registry – A dict keyed by module name whose values are the corresponding Logger bound to that module

Return type:

dict[str, Optional[logging.Logger]]

class polymerist.genutils.logutils.IOHandlers.MultiStreamFileHandler(filename: str | pathlib.Path, mode: str = 'a', encoding: str | None = None, delay: bool = False, errors: str | None = None, loggers: str | logging.Logger | Iterable[logging.Logger] | None = 'ALL', formatter: logging.Formatter = LOG_FORMATTER, proc_name: str = 'Process')[source]

Bases: logging.FileHandler

Class to simplify logging file I/O given multiple logger sources providing logging input Automatically reports process completion & runtime if process is successful, or detailed error traceback otherwise

Can spawn child processes to have multiple nested levels of logging to many partitioned output files for layered processes

proc_name: str = 'Process'
id: int
personal_logger: logging.Logger
parent: MultiStreamFileHandler | None = None
children: dict[int, MultiStreamFileHandler]
register_logger(logger: logging.Logger) None[source]

Add an individual Logger to the File Stream

unregister_logger(logger: logging.Logger) None[source]

Remove an individual Logger from the collection of linked Loggers

register_loggers(*loggers: list[logging.Logger]) None[source]

Record a new Logger and add the File handler to it - enables support for multiple Logger streams to a single file

unregister_loggers() None[source]

Purge all currently registered Loggers

subhandler(*args, **kwargs) MultiStreamFileHandler[source]

Generate a subordinate “child” process which reports back up to the spawning “parent” process once complete

propogate_msg(level: int, msg: str) None[source]

Propogate a logged message up through the parent tree

class polymerist.genutils.logutils.IOHandlers.MultiStreamFileHandlerFlexible(filedir: pathlib.Path | None = None, filename: str | pathlib.Path | None = None, mode: str = 'a', encoding: str | None = None, delay: bool = False, errors: str | None = None, loggers: str | logging.Logger | list[logging.Logger] | None = 'ALL', formatter: logging.Formatter = LOG_FORMATTER, proc_name: str = 'Process', write_timestamp: bool = True, timestamp: polymerist.genutils.logutils.timestamps.Timestamp = Timestamp())[source]

Bases: MultiStreamFileHandler

MSFHandler which is a bit more flexible (and lazy) when it comes to log file naming and creation Can either pass a log file path (as normal) or a directory into which to output the logfile If the latter is chosen, will create a logfile based on the specified process name, optionally adding a timestamp if desired

polymerist.genutils.logutils.IOHandlers.MSFHandler
polymerist.genutils.logutils.IOHandlers.MSFHandlerFlex