Update Advanced Python Logger
A feature-rich logging solution with file rotation, size-based cleanup, and configurable formatting.
Features
- вњ… Multi-level logging (INFO, WARN, ERROR, CRIT, DEBUG)
- рџ“Ѓ Automatic log rotation by size and age
- рџ“ќ Dual output (console + file) with toggle capability
- рџ§№ Automatic cleanup of old log files
- рџ› Exception-safe design
Installation
pip install upd-logger
Quick Start
from upd_logger import Logger
# Initialize
Logger.setup_logging(
log_dir="my_app_logs",
write_to_file=True,
max_log_size=10*1024*1024, # 10MB
max_log_age_days=7
)
# Usage
Logger("Application started", "info")
Logger("Important event", "warn")
Full Usage Examples
Basic Configuration
# Console-only logging
Logger.setup_logging(write_to_file=False)
# File logging with custom formats
Logger.setup_logging(
log_dir="logs"
)
Logging Examples
# Different log levels
Logger("Debug information", "debug")
Logger("Non-critical issue", "warn")
Logger("Critical failure!", "crit")
# Error handling
try:
risky_operation()
except Exception as e:
Logger(f"Operation failed: {str(e)}", "error")
Runtime Reconfiguration
# Switch to emergency console-only mode
Logger.setup_logging(write_to_file=False)
Logger("File logging disabled!", "warn")
Configuration Options
| Parameter | Default | Description |
|---|---|---|
log_dir |
"logs" |
Directory for log files |
write_to_file |
True |
Enable file logging |
auto_delete_logs |
True |
Enable auto delete |
max_log_size |
62914560 |
Max log size in bytes (60MB) |
max_log_age_days |
30 |
Max age of logs in days |
Best Practices
-
Initialize early - Call
setup_logging()at application startup -
Use proper levels:
debug- Diagnostic infoinfo- Regular operationswarn- Unexpected but recoverableerror- Failed operationscrit- Critical failures
-
Include context in messages:
# Good
Logger(f"User {user_id} failed login (attempt {attempt_count})", "warn")
# Bad
Logger("Something happened", "warn")
Advanced Features
Custom Cleanup Rules
# Keep logs for 1 day or max 1MB
Logger.setup_logging(
max_log_size=1024*1024,
max_log_age_days=1
)
Testing Integration
# In tests - disable file logging
Logger.setup_logging(write_to_file=False)
The README follows modern Python packaging standards and provides all necessary information at a glance while being detailed enough for advanced users.
Release files for upd-logger 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| upd_logger-1.0.0.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| upd_logger-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / upd_logger-1.0.0.tar.gz
| Download URL | upd_logger-1.0.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f3fbe3da305c1669a915674aad546b2c9b2bf996c6d9d25283aea202b82a7e5
|
|
BLAKE2b-256 checksum How to use checksums |
10854ad7cf5f560a0538da1c3a68bc13e35f9da09f45f10a5b8619bf6f790db1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|
Release files / upd_logger-1.0.0-py3-none-any.whl
| Download URL | upd_logger-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f7414694056e7f9094c9ec454c93303dd2e5572a1927d2b40ed2809e36d58559
|
|
BLAKE2b-256 checksum How to use checksums |
fb05e732c6ee1c6c8106a42299b3765b0cfc4003fbcf7f3279e33fdd46e7f782
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|