Skip to main content

A python package to stream your app logs to a telegram chat in realtime.

Project description

Telegram Logger

A simple yet powerful python package to send your app logs to a telegram chat in realtime.

Sample Image

Installing

pip3 install -U tglogging-black

Example Usage

Add TelegramLogHandler handler to your logging config.

import logging
from tglogging import TelegramLogHandler

# TelegramLogHandler is a custom handler which is inherited from an existing handler. ie, StreamHandler.

logging.basicConfig(
    level=logging.INFO,
    format="[%(asctime)s - %(levelname)s] - %(name)s - %(message)s",
    datefmt='%d-%b-%y %H:%M:%S',
    handlers=[
        TelegramLogHandler(
            token="12345678:AbCDEFGhiJklmNoPQRTSUVWxyZ", 
            log_chat_id=-10225533666,
            forum_msg_id=24,
            title="@AltCakeBot",
            ignore_match=["error: floodwait", "scheduler execution delayed"],
            update_interval=2, 
            minimum_lines=1, 
            pending_logs=200000),
        logging.StreamHandler()
    ]
)

logger = logging.getLogger(__name__)

logger.info("live log streaming to telegram.")

Parameters

token : A telegram bot token to interact with telegram API.

log_chat_id : Chat id of chat to which logs are to be sent.

forum_msg_id : [Optional] Forum Topic ID where to send the logs to.

title : a custom title you want to use in log message. Defaults to "TGLogger"

ignore_match : Specify what lines need to contain, in order to be ignored by TGLogger.

update_interval: Interval between two posting in seconds. Lower intervals will lead to floodwaits. Default to 5 seconds.

minimum_lines: Minimum number of new lines required to post / edit a message.

pending_logs: Maximum number of characters for pending logs to send as file. default to 200000. this means if the app is producing a lot of logs within short span of time, if the pending logs exceeds 200000 characters it will be sent as a file. change according to your app.

LICENSE

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

tglogging_black-0.1.8.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

tglogging_black-0.1.8-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file tglogging_black-0.1.8.tar.gz.

File metadata

  • Download URL: tglogging_black-0.1.8.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for tglogging_black-0.1.8.tar.gz
Algorithm Hash digest
SHA256 6b91236b7c06ec54b16dcc4befca23afb5829c3eb28abc2200622f45619093db
MD5 6e2e0e306836a441dfd55bc0bfccf132
BLAKE2b-256 23523094234cacb9bb41391cddf32995afb1e0cef8360ae035978510613e6096

See more details on using hashes here.

File details

Details for the file tglogging_black-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for tglogging_black-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e0316be7aa75cb7d1d0e15cb7761fda6fdfd5dfb2c5dabab7e0334bfb18c464e
MD5 cbbeb97e44a1484613578a8876023300
BLAKE2b-256 87582a868066d049d8845d1a8a4eb33a5a17e4768a93a11979f4f4a37c45d9bf

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