Skip to main content

Simple Telegram logging with zero dependencies.

Project description

telegram-logging

Simple Telegram logging with zero dependencies!

https://pypi.org/project/telegram-logging/

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")

Default Emojis:

Emoji Level
⚪️ DEBUG
🔵 INFO
🟠 WARNING
🔴 ERROR
🔥 CRITICAL

You can use your own set of emojis:

telegram

formatter = TelegramFormatter(
    format="[%(asctime)s %(name)s] %(levelname)8s\n\n%(message)s",
    datefmt="%d/%m/%Y %H:%M:%S",
    use_emoji=True,
    emoji_map={
        logging.DEBUG: "🐛",
        logging.INFO: "💡",
        logging.ERROR: "🚨",
    })

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_logging-1.0.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

telegram_logging-1.0.0-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page