logging

Logging factory and handlers

init_logger(name: str, log_dir: Path | None | Literal[False] = None, level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR'] | None = None, file_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR'] | None = None, log_file_n: int | None = None, log_file_size: int | None = None, width: int | None = None) Logger[source]

Make a logger.

Log to a set of rotating files in the log_dir according to name , as well as using the RichHandler for pretty-formatted stdout logs.

If this method is called from a process that isn’t the root process, it will create new rich and file handlers in the root noob logger to avoid deadlocks from threading locks that are copied on forked processes. Since the handlers will be different across processes, to avoid file access conflicts, logging files will have the process’s pid appended (e.g. noob_12345.log )

Parameters:
  • name (str) – Name of this logger. Ideally names are hierarchical and indicate what they are logging for, eg. noob.api.auth and don’t contain metadata like timestamps, etc. (which are in the logs)

  • log_dir (pathlib.Path) – Directory to store file-based logs in. If None, get from Config. If False , disable file logging.

  • level (LOG_LEVELS) – Level to use for stdout logging. If None , get from Config

  • file_level (LOG_LEVELS) – Level to use for file-based logging. If None , get from Config

  • log_file_n (int) – Number of rotating file logs to use. If None , get from Config

  • log_file_size (int) – Maximum size of logfiles before rotation. If None , get from Config

  • width (int, None) – Explicitly set width of rich stdout console. If None , get from Config

Returns:

logging.Logger