➡️ See a full example in examples/usage.py
🤖 How to create a Telegram bot
pip install telegram-logging
from telegram_logging import TelegramHandler, TelegramFormatter
formatter = TelegramFormatter(
fmt="[%(asctime)s %(name)s] %(levelname)8s\n\n%(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
use_emoji=True)
handler = TelegramHandler(
token="<Your bot token>",
chat_id="<Your chat id>")
handler.setFormatter(formatter)
*You can get a list of all available handler params here
import logging
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logger.info("Hi, here is some information")
These are the default emojis:
- ⚪️ DEBUG
- 🔵 INFO
- 🟠 WARNING
- 🔴 ERROR
- 🔥 CRITICAL
You can customize them however you want:
formatter = TelegramFormatter(
...
use_emoji=True,
emoji_map={
logging.DEBUG: "🐛",
logging.INFO: "💡",
logging.ERROR: "🚨",
})