Drowning in logs? If your Python applications generate a flood of log messages, it’s time to rethink your logging strategy. Introducing TimeBasedLogger, a Python library designed to bring peace and order back to your log files.
Log Less, See More
Traditional loggers write a message for every single event. This quickly becomes overwhelming in busy systems. TimeBasedLogger takes a different approach: time-based logging. Instead of logging every event, it logs only once per specified time interval. This keeps your logs concise and relevant, even under heavy load.
This project was inspired by John Scolaro’s insightful article, “Log by Time, not by Count“, which highlights the benefits of this approach.
Key Features
- Time-Based Logging: Logs only at your chosen interval (e.g., every 2 seconds).
- Max Logs per Interval: Set a limit to prevent bursts of logs.
- Pause/Resume: Control logging on the fly.
- Async Mode: High-performance background logging.
- Thread Safety: Safe for multi-threaded applications.
- Custom Log Levels & Filtering: Standard log levels and custom filtering.
- Structured Logging/Extra Fields: Add context to your logs.
- Custom Formatting: Tailor the log output to your needs.
- Exception Logging: Capture and log exceptions with tracebacks.
Installation
Install from PyPI:
pip install timebased-logger
Quick Usage
from timebased_logger import TimeBasedLogger
# Log only once per 2 seconds
logger = TimeBasedLogger(interval_seconds=2)
logger.log("Hello")
logger.log("World") # This won't log if called within 2 seconds
When is TimeBasedLogger Useful?
Consider using TimeBasedLogger if you have:
- IoT devices or sensors generating frequent events.
- Web/API servers with constant status checks.
- Background jobs with repetitive logging.
Why Choose TimeBasedLogger?
In high-volume environments, traditional logging can create massive, unmanageable log files. TimeBasedLogger solves this by logging only at specified intervals. This keeps your logs concise, making them easier to analyze and understand. And with its customizable features, you have full control over your logging strategy.
Give TimeBasedLogger a try and see how it can simplify your logging and improve your understanding of your application’s behavior.