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.

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.1.tar.gz (4.4 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.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tglogging-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/18.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for tglogging-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6b7a5bdfc1caec2dcbfe3310d5b52c8599c91bf59b319e35e370dd9d3973bd1a
MD5 4380c874b13044a338b0cfec84381611
BLAKE2b-256 7799bf479b3fcb8ecbec435b695a30b16f48cf4c7267621e79aee4a62a4f7879

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tglogging-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/18.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for tglogging-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a08538efb8b0cab59ce77e92cd2250df421a9a23e2d028b77ddc1d6876cf420a
MD5 1ee0df4d4e5caa5bda9e729988bac47f
BLAKE2b-256 fc38aa04791a2481b80ad5534850f3205f711d3b55c36d14200d1356f190ca67

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