Skip to main content

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

Metadata

Release files for tglogging-black 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tglogging-black 0.1.8
File Size Uploaded
tglogging_black-0.1.8.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tglogging-black 0.1.8
File Interpreter ABI Platform
tglogging_black-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / tglogging_black-0.1.8.tar.gz

Download URL tglogging_black-0.1.8.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6b91236b7c06ec54b16dcc4befca23afb5829c3eb28abc2200622f45619093db
BLAKE2b-256 checksum
How to use checksums
23523094234cacb9bb41391cddf32995afb1e0cef8360ae035978510613e6096
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Release files / tglogging_black-0.1.8-py3-none-any.whl

Download URL tglogging_black-0.1.8-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0316be7aa75cb7d1d0e15cb7761fda6fdfd5dfb2c5dabab7e0334bfb18c464e
BLAKE2b-256 checksum
How to use checksums
87582a868066d049d8845d1a8a4eb33a5a17e4768a93a11979f4f4a37c45d9bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page