Skip to content

patera.logging

See the logging guide.

Logging module

DefaultLoggerConfig

Bases: LoggerConfigBase

Configuration of Patera's default console logger (DEFAULT_LOGGER).

Unknown keys are rejected, so a misspelt setting fails at startup.

LogFilesConfig

Bases: BaseModel

Configuration of the application's JSON Lines log files (LOG_FILES).

normalize_level classmethod

normalize_level(value: Any) -> Any

Accepts case-insensitive level names from environment files.

require_jsonl_suffix classmethod

require_jsonl_suffix(value: str) -> str

Rotated files are recognised by the .jsonl suffix.

JsonLogFiles

JsonLogFiles(config: LogFilesConfig, root_path: Union[str, Path], default_logger_name: str = 'Patera Logger')

Writes log records to rotating JSON Lines files and reads them back.

The active file is PATH. Rotated files sit next to it and carry the rotation time in their name, for example patera.2026-10-09_13-25-00_123456.jsonl.

sink_id property

sink_id: Optional[int]

Loguru handler id while the sink is attached.

attach

attach() -> Optional[int]

Adds the file sink to Loguru. Returns the handler id, or None if disabled.

detach

detach() -> None

Removes the file sink from Loguru.

files

files() -> list[Path]

Existing log files, newest first; the active file comes first.

read

read(limit: Optional[int] = None) -> list[dict[str, Any]]

Returns the newest records, oldest first. At most limit records are returned; the default is READ_LIMIT. Lines that are not complete JSON objects, such as a line still being written, are skipped.

read_async async

read_async(limit: Optional[int] = None) -> list[dict[str, Any]]

Same as read(), but runs the file access in a worker thread.

LoggerBase

LoggerBase(app: AppT)

Bases: ABC, Generic[AppT]

Base template for configuring a Loguru sink.

Settings are read from the configuration field named after the class in upper snake case (AuditLogger -> AUDIT_LOGGER). Subclasses override get_sink() or the other getters to change how the sink is set up.

configs_name property

configs_name: str

Returns class name as upper snake case (HTTPLogger -> HTTP_LOGGER)

validate_configs

validate_configs(configs: dict[str, Any]) -> dict[str, Any]

Validates the logger's settings with configs_model (LoggerConfigBase by default).

LoggerConfig

Bases: BaseModel

Base config model for loggers

normalize_sink classmethod

normalize_sink(v)

Accept case-insensitive sink aliases and convert to canonical form.

normalize_level classmethod

normalize_level(v)

Accept enum instances or case-insensitive strings from .env files.

LogLevel

Bases: StrEnum

logger

logger(name: Optional[str] = None)