106
This project provides a production-grade Telegram destination for Python's standard logging module. It allows you to send logs directly to a Telegram chat asynchronously, ensuring that your application's performance is not impacted by slow or unavailable Telegram Bot API responses. The handler includes robust features such as batching of logs, retries with exponential backoff, handling of rate limits (429 errors), splitting of oversized messages, back-pressure management for bounded queues, and automatic escaping of content for Telegram's formatting modes (MarkdownV2 or HTML).
Install the package using pip:
pip install tg-logging-handlerRequires Python 3.10+.
Integrate the handler into your Python logging configuration:
import logging from tg_logging_handler import TelegramLoggingHandler # Reads TG_TOKEN / TG_CHAT_ID from the environment. logging.getLogger().addHandler(TelegramLoggingHandler()) logging.error('Something broke') # delivered to your Telegram chatBuilt with