thinlog.formatters package#
Log formatters for JSON, plain-text, and Telegram output.
- class thinlog.formatters.JsonFormatter(show_locals: bool = False, **kwargs: Any)[source]#
Bases:
FormatterSerialize the full log record as a JSON string.
Exception tracebacks are converted to structured dicts using
structlog.tracebacks.ExceptionDictTransformer, and stack-info frames are extracted viaparse_stack_info().- Parameters:
show_locals – If
True, local variables are included in exception tracebacks.
- formatException(ei: tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]) str[source]#
Format exception info as a JSON string, falling back to the standard formatter.
- classmethod format_exception(ei: tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]) Any[source]#
Transform exception info into a structured dict via structlog.
- classmethod format_record(record: LogRecord) dict[str, Any][source]#
Convert a
LogRecordto a plain dict.Handles
exc_info(via structlog transformer) andstack_info(viaparse_stack_info()).
- transformer: ClassVar[ExceptionDictTransformer]#
- class thinlog.formatters.MsgFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#
Bases:
FormatterReturn just the formatted message string, discarding all other record fields.
- class thinlog.formatters.TelegramFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#
Bases:
FormatterFormat log records as HTML
<code>blocks for the Telegram Bot API.Messages that fit within
MAX_MESSAGE_LEN(4096 chars) are sent as regular messages. Longer messages are split: a truncated caption (up toMAX_CAPTION_LENchars) is sent alongside the full text as a document attachment.- MAX_CAPTION_LEN = 1024#
- MAX_MESSAGE_LEN = 4096#
- format_advanced(record: LogRecord) tuple[str | None, str][source]#
Return a
(caption, text)tuple for Telegram delivery.If the message fits in a single Telegram message, caption is
Noneand text contains the full HTML-wrapped content.If the message is too long, caption is a truncated HTML preview and text is the raw full-length message (sent as a document).
- parse_mode = 'HTML'#