liberata_metrics.configure_logging

liberata_metrics.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”)