emrpy.logging.logger_config
Logger Configuration Utilities
Safe, high-level logging setup for scripts and notebooks with support for colorised console output and optional rotating file handlers.
Functions
|
Configure a logger with console and optional rotating file output. |
|
Return a namespaced logger with a NullHandler attached. |
- emrpy.logging.logger_config.configure(name='emrpy', *, level=20, log_dir=None, filename='emrpy.log', rotate_bytes=5000000, backups=3, fmt='%(asctime)s %(levelname)s ▶ %(name)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', coloured_console=True)
Configure a logger with console and optional rotating file output.
This function sets up a logger with colorised console output and (optionally) a rotating file handler. Safe to call multiple times without duplicating handlers.
- Return type:
Logger
Parameters:
- namestr, default “emrpy”
Logger name to configure.
- levelint or str, default logging.INFO
Logging level (e.g., “DEBUG”, “INFO”).
- log_dirstr or Path, optional
Directory to store log files. Defaults to $EMRPY_LOG_DIR or “logs”.
- filenamestr, default “emrpy.log”
Name of the log file (if file logging is enabled).
- rotate_bytesint, default 5_000_000
Max file size before rotation (in bytes). Set to 0 to disable file logging.
- backupsint, default 3
Number of backup files to keep when rotating.
- fmtstr, default DEFAULT_FMT
Log message format string.
- datefmtstr, default DEFAULT_DATEFMT
Date format string.
- coloured_consolebool, default True
Whether to use colorlog for console output.
Returns:
: logging.Logger
Configured logger instance.
Examples:
>>> # Script with file logging >>> configure(level="INFO", log_dir="logs", filename="pipeline.log")
>>> # Notebook console-only logging >>> configure(level="DEBUG", rotate_bytes=0)
>>> log = get_logger(__name__) >>> log.info("Logger ready ✔")
- emrpy.logging.logger_config.get_logger(name='emrpy')
Return a namespaced logger with a NullHandler attached.
This function ensures safe logger creation without modifying the root logger. Ideal for use in libraries or scripts where central configuration is handled separately.
- Return type:
Logger
Parameters:
- namestr, default “emrpy”
The name of the logger to retrieve.
Returns:
: logging.Logger
A logger instance with a NullHandler attached if none exists.
Examples:
>>> from emrpy.logging import get_logger >>> log = get_logger(__name__) >>> log.debug("This won't output unless configured.")