Skip to main content

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?

Metadata

Release files for tg-logger 3.3

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

Source distribution (sdist)

Source distribution for tg-logger 3.3
File Size Uploaded Provenance Actions
tg_logger-3.3.tar.gz 4.5 kB Without provenance Details for tg_logger-3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tg-logger 3.3
File Interpreter ABI Platform Actions
tg_logger-3.3-py3-none-any.whl Python 3 none any Details for tg_logger-3.3-py3-none-any.whl

Total release size: 10.0 kB

Release files / tg_logger-3.3.tar.gz

Download URL tg_logger-3.3.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
42c576d442229b537de276e77d9613fea7e15fbc3a5212574d9096c5fb26a6d5
BLAKE2b-256 checksum
How to use checksums
c20bea1fa72db9fb4c513d492aede24b360fa461c071af57df1912a4d6f5d967
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / tg_logger-3.3-py3-none-any.whl

Download URL tg_logger-3.3-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbdd4330b71fa16a67644bac24969dfc6ed643f1e748c80b7b0706ecb32122ad
BLAKE2b-256 checksum
How to use checksums
d6236ae5e38dc5d78e5319a510207f9531c98733d23b198725fc36f6c6319e77
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for tg-logger 3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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