thinlog.log module#

Logger adapter that converts keyword arguments into extra fields.

class thinlog.log.KeywordFriendlyLogger(logger: Logger, extra: dict[str, Any] | None = None)[source]#

Bases: LoggerAdapter[Logger]

A logging.LoggerAdapter that passes arbitrary keyword arguments as extra fields.

Standard logging requires extra data to be wrapped in an extra dict. KeywordFriendlyLogger lets callers pass keyword arguments directly – they are automatically moved into extra so that filters, formatters, and handlers can access them as record attributes.

Parameters:
  • logger – The underlying logging.Logger to adapt.

  • extra – Optional default extra fields attached to every record.

ignored_meta_keys = ('exc_info', 'stack_info', 'stacklevel')#
process(msg: Any, metadata: MutableMapping[str, Any]) tuple[Any, MutableMapping[str, Any]][source]#

Move keyword arguments into the extra dict.

Keys listed in ignored_meta_keys are left in metadata so that the standard logging machinery can handle them.

Parameters:
  • msg – The log message.

  • metadata – Keyword arguments passed to the logging call.

Returns:

A (msg, metadata) tuple ready for the underlying logger.