Skip to main content

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

Project description

Telegram Logger

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

Sample Image

Installing

pip3 install tglogging

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, 
            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 send.

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 send 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-0.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tglogging-0.0.4-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file tglogging-0.0.4.tar.gz.

File metadata

  • Download URL: tglogging-0.0.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for tglogging-0.0.4.tar.gz
Algorithm Hash digest
SHA256 5bad575089f09fde2630793bf058e2688b02d5202c335d321000774ada991dcd
MD5 358b2fa4fb34c4720120e6294445190c
BLAKE2b-256 7e48b309ebc92055dea7f37566ebc867c693fdc8349bb6681b3b588bc9768a69

See more details on using hashes here.

File details

Details for the file tglogging-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: tglogging-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for tglogging-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f8386a4897a866b1c39df7eee4010f402e5ec1bb612f6eba654bf69c884f39d5
MD5 ebe94d63648a27248de4e38505ee3a78
BLAKE2b-256 30a0d0e33586a4539ca684188e7ad722ab59c183ecab30597fe2f96396310fe1

See more details on using hashes here.

Supported by

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