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_diraccording toname, as well as using theRichHandlerfor 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
pidappended (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.authand don’t contain metadata like timestamps, etc. (which are in the logs)log_dir (
pathlib.Path) – Directory to store file-based logs in. IfNone, get fromConfig. IfFalse, disable file logging.level (
LOG_LEVELS) – Level to use for stdout logging. IfNone, get fromConfigfile_level (
LOG_LEVELS) – Level to use for file-based logging. IfNone, get fromConfiglog_file_n (
int) – Number of rotating file logs to use. IfNone, get fromConfiglog_file_size (
int) – Maximum size of logfiles before rotation. IfNone, get fromConfigwidth (
int,None) – Explicitly set width of rich stdout console. IfNone, get fromConfig
- Returns: