thinlog.formatters.telegram module#
HTML formatter for Telegram messages with length-aware splitting.
- class thinlog.formatters.telegram.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'#