Skip to main content

It is a library that allows you to send logging logs to Telegram

Project description

Telegram Bot Logger

PyPI Version Python Version

Telegram Bot Logger is a Python library that allows you to send logging logs to Telegram using the Bot API. It simplifies the process of integrating Telegram bot notifications into your Python applications, making it easy to monitor and manage your application's logs.

Installation

You can install telegram_bot_logger using pip:

pip install telegram-bot-logger

Usage

import telegram_bot_logger

import logging


logger = logging.getLogger("telegram_bot_logger_example")

handler = telegram_bot_logger.TelegramMessageHandler(
    bot_token = "YOUR_BOT_TOKEN", # Required; bot's token from @BotFather
    chat_ids = [
        12345678,
        "@username"
    ], # Required; you can pass id as integer or username as string
    api_server = telegram_bot_logger.api_server.TelegramAPIServer(
        base = "https://api.telegram.org/bot{bot_token}/{method}"
    ), # Optional; set by default
    format_type = "text" or "TEXT" or telegram_bot_logger.formatters.FormatType.TEXT, # Optional; also can be "DOCUMENT", by default it is "TEXT"
    document_name_strategy = "timestamp" or "TIMESTAMP" or telegram_bot_logger.formatters.DocumentNameStrategy.TIMESTAMP, # Optional; used to define documents' names; also can be "ARGUMENT", by default it is "TIMESTAMP"
    proxies = {
        "http://": "http://localhost:8080"
    } or "http://localhost:8080", # Optional; "dict[scheme, url]" or just "url"
    formatter = formatters.TelegramHTMLTextFormatter(), # Optional; you can create your own class inherited from formatters.TelegramBaseFormatter and pass it
    additional_body = {
        "reply_to_message_id": 1
    } # Optional; additional request body on sendMessage and sendDocument
)

logger.setLevel(
    level = logging.DEBUG
)

logger.addHandler(handler)


logger.debug("debug-message")
# Or:
logger.debug("debug-message", extra={"document_name": 123}) # 123 is an argument; to use this feature you need to set format_type = formatters.FormatType.DOCUMENT and document_name_strategy = formatters.DocumentNameStrategy.ARGUMENT

Replace YOUR_BOT_TOKEN and chat_ids with your actual bot token and chat IDs. You can obtain a bot token by creating a new bot on Telegram and obtaining it from the BotFather.

Stay Updated

For the latest news and updates, follow my Telegram Channel.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

telegram_bot_logger-0.0.3.post0-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file telegram_bot_logger-0.0.3.post0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_bot_logger-0.0.3.post0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8b4015a682df30ab3c18e4ea0135fc137afbb6a9a02d41d786a5bc41e7b75ab6
MD5 f8be5995699596040c0d0d3b53b08014
BLAKE2b-256 53e6d5516f1051bf419651d275db568c575e0ea9ffdbacbf7b44933ab229990e

See more details on using hashes here.

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