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: Formatter

Format 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 to MAX_CAPTION_LEN chars) is sent alongside the full text as a document attachment.

MAX_CAPTION_LEN = 1024#
MAX_MESSAGE_LEN = 4096#
format(record: LogRecord) str[source]#

Format the record message, pretty-printing JSON if possible.

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 None and 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'#