Skip to content

lbltavares/telegram-logging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Telegram logging with zero dependencies!

Usage:

➡️ See a full example in examples/usage.py

🤖 How to create a Telegram bot

Install:

pip install telegram-logging

Import:

from telegram_logging import TelegramHandler, TelegramFormatter

Create a Formatter and a Handler:

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

Use it:

import logging

logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)


logger.info("Hi, here is some information")

Emojis:

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: "🚨",
    })

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages