polymerist.genutils.logutils.IOHandlers
Tools for simplifying logging from multiple sources
Attributes
Classes
Class to simplify logging file I/O given multiple logger sources providing logging input |
|
MSFHandler which is a bit more flexible (and lazy) when it comes to log file naming and creation |
Functions
|
Gets all registered Loggers by module |
|
|
|
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.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.FileHandlerClass 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]
- 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
- subhandler(*args, **kwargs) MultiStreamFileHandler[source]
Generate a subordinate “child” process which reports back up to the spawning “parent” process once complete
- 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:
MultiStreamFileHandlerMSFHandler 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