Skip to main content

Teletracker

PyPI version License

A bridge between Python's logging module and Telegram: send log messages and files directly to your chat.

📦 Installation

Install the package from PyPI with:

pip install teletracker

🚀 Overview

The library provides a handler for Python's logging framework and a dedicated class for sending files via Telegram.

Main Classes

UnifiedTgLogger

Inherits from logging.Handler; sends formatted log messages via Telegram.

Constructor:

UnifiedTgLogger(
    token: str,
    users: List[int],
    timeout: int = 10,
    level: int = logging.INFO,
    log_emoji: Optional[str] = None,
    use_random_log_emoji: bool = False,
    disable_notification: bool = False,
    disable_web_page_preview: bool = False
)

Parameters:

  • token – Telegram bot token.
  • users – List of chat_id to send logs to.
  • timeout – HTTP timeout in seconds.
  • level – Log level (default INFO).
  • log_emoji – Fixed emoji for all messages.
  • use_random_log_emoji – If True, chooses a random emoji.
  • disable_notification – Send silently.
  • disable_web_page_preview – Disable link previews.

Methods:

  • get_emoji(levelno: int) -> str Returns the emoji based on the log level or settings.

  • emit(record: logging.LogRecord) Formats the record with HTML and sends the message to the bot. If exc_info is present, includes the traceback in a <pre><code> block.

  • send_file(file_path: str, caption: str = '') Sends a file (document or image); delegates to TgFileLogger.

  • setLevel(level: int) Dynamically changes the log level of the handler.

  • update_users(users: List[int]) Updates the list of users (chat_id) for messages and files.

TgFileLogger

Dedicated class for sending files via Telegram. Can be used directly or through UnifiedTgLogger.

Constructor:

TgFileLogger(
    token: str,
    users: List[int],
    timeout: int = 10
)

Main method:

  • send(file_path: str, caption: str = '') Sends a document or image with an optional caption.

📖 Usage Examples

Simple Logging

import logging
from teletracker.unified_logger import UnifiedTgLogger

logger = logging.getLogger('app')
logger.setLevel(logging.DEBUG)

handler = UnifiedTgLogger(
    token='YOUR_BOT_TOKEN_HERE',  # Replace with your bot token
    users=[YOUR_CHAT_ID_HERE]     # Replace with your chat ID
)
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
logger.addHandler(handler)

logger.info('Application started')
logger.error('An error was recovered')

try:
    1/0
except Exception:
    logger.exception('Division by zero occurred')

Sending Files

from teletracker.unified_logger import UnifiedTgLogger

# Assuming 'token' and 'users' are defined as in the simple logging example
# token = 'YOUR_BOT_TOKEN_HERE'
# users = [YOUR_CHAT_ID_HERE]

file_logger = UnifiedTgLogger(token, users) # Or TgFileLogger(token, users)
file_logger.send_file(
    'report.txt',
    caption='Daily report'
)

🙏 Acknowledgements

This project was originally forked from otter18/tg_logger. The original library provided a great starting point. This fork was created because the original project was no longer actively maintained and lacked certain features. While the codebase has been significantly refactored and rewritten to add new functionalities and improvements, we acknowledge the foundational work of the original author.

📜 License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Metadata

Release files for teletracker 0.0.1

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

Source distribution (sdist)

Source distribution for teletracker 0.0.1
File Size Uploaded Provenance Actions
teletracker-0.0.1.tar.gz 8.2 kB Without provenance Details for teletracker-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for teletracker 0.0.1
File Interpreter ABI Platform Actions
teletracker-0.0.1-py3-none-any.whl Python 3 none any Details for teletracker-0.0.1-py3-none-any.whl

Total release size: 17.9 kB

Release files / teletracker-0.0.1.tar.gz

Download URL teletracker-0.0.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
030071b335fbab37e8321aebf59e20c30e4d04737e25bc35acfc77544e808ca1
BLAKE2b-256 checksum
How to use checksums
6f022d995ab2ce61ac4ee54239885189717aa1d7bd67942a66a587b79efa64b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / teletracker-0.0.1-py3-none-any.whl

Download URL teletracker-0.0.1-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f81f0d8438fcded5f5b001613533a22839411b493a73c80085ba205e9fc7fe5a
BLAKE2b-256 checksum
How to use checksums
250114323ed13e82c8936af84cf0e94c427c736529ad58b513bb04158866c65c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for teletracker 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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