Minimal Python logger with Telegram notifications
Project description
easy_tg_logger
Fast, minimal async logger for local files with optional Telegram alerts. Zero dependencies (stdlib only).
Install
pip install easy_tg_logger
Usage
from pytelegram_logger import init_telegram_logger, log, shutdown_logger
init_telegram_logger(name="my_app")
log("App started")
log("Database error", is_error=True)
shutdown_logger() # optional, flushes pending logs
With Telegram alerts
init_telegram_logger(
name="my_app",
telegram_token_logs="BOT_TOKEN_1", # routine logs
telegram_token_errors="BOT_TOKEN_2", # error alerts
telegram_chat_ids=["-1001234567890"],
)
log("Payment received", send_telegram=True)
log("Critical failure", is_error=True, send_telegram=True)
Two tokens = two channels: routine logs stay separate from high-priority error alerts.
API
init_telegram_logger(name, ...)
| Argument | Default | Description |
|---|---|---|
name |
— | Required. Unique instance id (e.g. "api", "worker_1"). |
log_dir |
"logs" |
Directory for log files. |
telegram_token_logs |
None |
Bot token for routine logs. |
telegram_token_errors |
None |
Bot token for errors. |
telegram_chat_ids |
[] |
List of chat IDs. |
retention_days |
30 |
Auto-delete files older than N days. |
queue_maxsize |
10000 |
Max pending messages per queue. |
log(message, is_error=False, send_telegram=False, save=True)
is_error=True→ error file + error tokensend_telegram=True→ also send to Telegramsave=False→ Telegram only, no file
shutdown_logger()
Graceful shutdown: drains queues and closes files. Optional but recommended.
get_dropped_count(sink=None)
Messages dropped because a queue was full (logging never blocks the caller).
get_dropped_count() # total (disk + Telegram)
get_dropped_count("file") # local logs lost ← the one that matters
get_dropped_count("telegram") # Telegram alerts lost
How it works
- Disk and network are isolated. Separate queue + worker each, so a slow or down Telegram never delays local logs. The file is the critical path: fast and reliable.
- Non-blocking.
log()drops and counts when a queue is full instead of freezing your app. - Crash-safe. Every line is flushed to disk immediately (durability over throughput).
- Daily rotation per named instance, with auto-cleanup after
retention_days.
logs/
├── my_app_logs_2025_01_21.log
├── my_app_errors_2025_01_21.log
└── worker_1_logs_2025_01_21.log
Requirements
- Python 3.10+
- No external dependencies
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_tg_logger-0.1.0.tar.gz.
File metadata
- Download URL: easy_tg_logger-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f321be755f1d47a336b60c2f926e4662662e6654f4c10af81b433046a65bb86
|
|
| MD5 |
67110d1be734540716f79dbb7d2003ff
|
|
| BLAKE2b-256 |
312fb5c83247ed2527727aee9ba662a1ad29ba461568f6a728351af0997c7bbc
|
File details
Details for the file easy_tg_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: easy_tg_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9a68d716e93b44194f1d84469bcd182cae8bb25fdd6cc41f2dabfc99a8a8f51
|
|
| MD5 |
1439e30d99d13c5ea51a8139f640f0a3
|
|
| BLAKE2b-256 |
c640c1d5a59796156b623132c5e8aa07d6bda2f5f5e037442bc60f5983ad7c60
|