liberata_metrics.logging module
- liberata_metrics.logging.configure_logging(level: str | None = None, log_file: str | None = None, max_bytes: int = 10000000, backup_count: int = 5, fmt: str | None = None) None[source]
Configure application-level logging for scripts/CLIs.
Call this once from top-level entrypoints (scripts, CLI) before performing work.
- Parameters:
level (Optional[str]) – Logging level name (e.g., “DEBUG”, “INFO”). If None, reads from environment variable LOG_LEVEL or defaults to “INFO”.
log_file (Optional[str]) – Path to a rotating log file. If provided, a RotatingFileHandler is added. Parent directories are created if necessary.
max_bytes (int) – Maximum bytes per log file before rotation.
backup_count (int) – Number of rotated log files to keep.
fmt (Optional[str]) – Optional log format string. If None, a sensible default is used.
Notes
This function configures the root logger. Library modules should not call this; only application code (scripts or CLI entrypoints) should configure logging.
Multiple calls are safe: if the root logger already has handlers, the function sets the level and returns early to avoid duplicate handlers in interactive runs.
Example
from liberata_metrics.logging import configure_logging configure_logging(level=”DEBUG”, log_file=”logs/run.log”)
- liberata_metrics.logging.get_logger(name: str | None = None) Logger[source]
Return a library logger.
- Usage (inside library modules):
logger = get_logger(__name__) logger.debug(“message”)
This logger installs a NullHandler by default so importing the library does not configure application logging or emit output. Application code (scripts/CLI) should call configure_logging() once at startup to enable handlers/formatting.
- Parameters:
name (Optional[str]) – Optional module name to append to the library logger root. If provided the returned logger name will be “liberata_metrics.<name>”.
- Returns:
Configured logger object (may carry NullHandler by default).
- Return type:
logging.Logger