Skip to content

cmem_client.models.logging_config¤

Models for the configuration of the logging module

Client.configure_logging_from_dict() and configure_logging_from_json() validate their input against these models before handing it to logging.config.dictConfig(), so a malformed logging configuration is rejected with a readable error instead of failing inside the standard library. The models mirror the dictConfig schema and allow extra keys, so anything dictConfig understands stays usable.

Classes:

Attributes:

  • LogLevel – Levels accepted in a logging configuration, including the client’s own TRACE.

FormatterConfig¤

Bases: BaseModel

Formatter configuration.

Attributes:

  • format (str) – Format string of the log records, e.g. "%(asctime)s - %(name)s - %(levelname)s - %(message)s".
  • datefmt (str | None) – Format string for the timestamp, or None for the default.

datefmt¤

datefmt: str | None = None

format¤

format: str

HandlerConfig¤

Bases: BaseModel

Handler configuration.

Attributes:

  • class_ (str) – Dotted path of the handler class, e.g. logging.StreamHandler. Written as class in the configuration itself.
  • level (LogLevel | None) – Lowest level this handler emits, or None to inherit from the logger.
  • formatter (str | None) – Name of the formatter to use, referring to a key of formatters.
  • filename (str | None) – File the handler writes to, for the file based handlers.

class_¤

class_: str = Field(..., alias='class')

filename¤

filename: str | None

formatter¤

formatter: str | None

level¤

level: LogLevel | None

LogLevel¤

LogLevel = Literal['TRACE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']

Levels accepted in a logging configuration, including the client’s own TRACE.

LoggerConfig¤

Bases: BaseModel

Logger configuration.

Attributes:

  • level (LogLevel | None) – Lowest level this logger passes on, e.g. DEBUG.
  • handlers (list[str] | None) – Names of the handlers to attach, referring to keys of handlers.

handlers¤

handlers: list[str] | None

level¤

level: LogLevel | None

LoggingConfig¤

Bases: BaseModel

Logging configuration. Allows for extra fields but validates the most common fields.

Attributes:

  • version (int) – Schema version of the configuration. dictConfig only knows 1, and anything else is rejected.
  • disable_existing_loggers (bool) – Whether loggers which already exist are switched off. Setting this silences libraries that configured logging before the client.
  • formatters (dict[str, FormatterConfig] | None) – Formatters of the configuration, keyed by name.
  • handlers (dict[str, HandlerConfig] | None) – Handlers of the configuration, keyed by name.
  • loggers (dict[str, LoggerConfig] | None) – Loggers of the configuration, keyed by logger name. Configure cmem_client.client to cover the whole library at once.
  • root (LoggerConfig | None) – Configuration of the root logger.

Functions:

check_version¤

check_version(v)

Ensure version is always 1.

disable_existing_loggers¤

disable_existing_loggers: bool

formatters¤

formatters: dict[str, FormatterConfig] | None

handlers¤

handlers: dict[str, HandlerConfig] | None

loggers¤

loggers: dict[str, LoggerConfig] | None

model_config¤

model_config = {'extra': 'allow'}

root¤

root: LoggerConfig | None

version¤

version: int = 1

Comments