Skip to main content

A tool to bridge python logging and user files to telegram bot

Project description

tg_logo Telegram logger GitHub Repo stars

Pypi version Downloads GitHub Documentation Status

Bridging python logging and files to tg bot

Documentation is available at Read the Docs

Demo is available @tg_logger_demo_bot, [repo]

intro_img

🗂 Table of Contents

🚀 Installation & Usage

  • Available by pip install tg-logger
  • Use with import tg_logger

📱 Screenshot

example_scr

📖 Examples

Simple logging

import logging
import tg_logger

# Telegram data
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
users = [1111111111]

# Base logger
logger = logging.getLogger('foo')
logger.setLevel(logging.INFO)

# Logging bridge setup
tg_logger.setup(logger, token=token, users=users)

# Test
logger.info("Hello from tg_logger by otter18")

Flask logging

from flask import Flask
import logging
import tg_logger

# Telegram data
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
users = [1111111111]

# Flask app setup
app = Flask(__name__)

app.logger.setLevel(logging.ERROR) # flask logger
tg_logger.setup(app.logger, token=token, users=users) # bridge setup


@app.route('/')
def hello_world():
    return 'Hello, World!'


if __name__ == '__main__':
    app.run()

Setting extra parameters to handler

import logging
import tg_logger

# Telegram data
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
users = [1111111111]

# Base logger
logger = logging.getLogger('foo')
logger.setLevel(logging.INFO)

# Logging bridge setup
handler = tg_logger.setup(logger, token=token, users=users)

# Setting extra params
handler.setLevel(logging.DEBUG)

# Test
logger.info("Hello from tg_logger by otter18")

TgFileLogger example

import tg_logger

# Telegram data
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
users = [1111111111]

# TgFileLogger example
tg_files_logger = tg_logger.TgFileLogger(
    token=token,  # tg bot token
    users=users,  # list of user_id
    timeout=10  # 10 seconds by default
)

file_name = "test.txt"
with open(file_name, 'w') as example_file:
    example_file.write("Hello from tg_logger by otter18")

tg_files_logger.send(file_name, "Test file")

🔎 FQA

How to create a telegram bot?

How to get token and user_id?

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

tg_logger-3.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

tg_logger-3.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file tg_logger-3.3.tar.gz.

File metadata

  • Download URL: tg_logger-3.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.7

File hashes

Hashes for tg_logger-3.3.tar.gz
Algorithm Hash digest
SHA256 42c576d442229b537de276e77d9613fea7e15fbc3a5212574d9096c5fb26a6d5
MD5 9119d1a73ee1053415e3af324fb66055
BLAKE2b-256 c20bea1fa72db9fb4c513d492aede24b360fa461c071af57df1912a4d6f5d967

See more details on using hashes here.

File details

Details for the file tg_logger-3.3-py3-none-any.whl.

File metadata

  • Download URL: tg_logger-3.3-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.7

File hashes

Hashes for tg_logger-3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bbdd4330b71fa16a67644bac24969dfc6ed643f1e748c80b7b0706ecb32122ad
MD5 d171f23098b4faa2df382db4d147d545
BLAKE2b-256 d6236ae5e38dc5d78e5319a510207f9531c98733d23b198725fc36f6c6319e77

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