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.3.tar.gz (4.5 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.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tglogging-0.0.3.tar.gz
  • Upload date:
  • Size: 4.5 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.3.tar.gz
Algorithm Hash digest
SHA256 4ac99ad5111ad44d0e67d5f2d317f2ed37ae25aa2f81ef8e73d248e944f0969f
MD5 897e20f33816e2bec008c770d066dbc5
BLAKE2b-256 062fd97372360c2de11e51c7154711a2c99613952176e2b9998f51df4dcdc64f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tglogging-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9d62330a20e5f79ddba1810721efa6ab140fec0401bbff6f3f9ebcf2b288aaab
MD5 439a046c14499779bd16d9701f85873a
BLAKE2b-256 a6da614b37d25e43bd818c7cf4ff8bba0c688e58adbe768a9be9235b24deca29

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