A feature-rich logging solution with file rotation, size-based cleanup, and configurable formatting.
Project description
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.
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 upd_logger-1.0.0.tar.gz.
File metadata
- Download URL: upd_logger-1.0.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f3fbe3da305c1669a915674aad546b2c9b2bf996c6d9d25283aea202b82a7e5
|
|
| MD5 |
126ff736f9b5c1231520312691d44668
|
|
| BLAKE2b-256 |
10854ad7cf5f560a0538da1c3a68bc13e35f9da09f45f10a5b8619bf6f790db1
|
File details
Details for the file upd_logger-1.0.0-py3-none-any.whl.
File metadata
- Download URL: upd_logger-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7414694056e7f9094c9ec454c93303dd2e5572a1927d2b40ed2809e36d58559
|
|
| MD5 |
cc0827a67f827b10afa8f7e919cc9208
|
|
| BLAKE2b-256 |
fb05e732c6ee1c6c8106a42299b3765b0cfc4003fbcf7f3279e33fdd46e7f782
|