Ti

TimeBasedLogger – Python Logger That Logs Based on Time

Hacker News

TimeBasedLogger – Python Logger That Logs Based on Time

What is TimeBasedLogger? TimeBasedLogger is a simple but production-grade Python logging library that changes how you manage your logs: instead of logging on every message, it lets you log only once per specified time interval. This can greatly reduce log spam in high-frequency systems, making logs more meaningful and easier to parse. Inspiration & Acknowledgement This project was directly inspired by John Scolaro’s article, "[Log by Time, not by Count]( https://johnscolaro.xyz/blog/log-by-time-not-by-count )". The blog post argues convincingly for a time-based logging approach, especially in systems that process large volumes of events rapidly. Its clear explanation and practical pseudocode examples helped shape the concept and motivation behind TimeBasedLogger. Big thanks to John Scolaro for articulating the challenges and benefits around logging strategies so effectively. Key Features Time-Based Logging: Emits logs only at your chosen time interval (e.g., every 2 seconds), regardless of message volume. Max Logs per Interval: Optionally set a cap—never exceed a set number of logs during each interval. Pause/Resume: Easily pause or resume logging with built-in controls. Async Mode: High-performance background logging supports batching for busy loops or async workflows. Thread Safety: Optional locking for multi-threaded environments. Custom Log Levels & Filtering: Full support for standard levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) and custom filtering. Structured Logging/Extra Fields: Add contextual data to logs for easy parsing and analysis. Custom Formatting: Flexible message formats using {level}, {asctime}, {message}, and any additional fields. Exception Logging: Log tracebacks with exc_info=True—no more silent error hiding. Installation PyPI: bash pip install timebased-logger Manual: Download and add timebased_logger.py to your project. Quick Usage Examples python 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 Log Levels python logger = TimeBasedLogger(level='WARNING') logger.info("Not logged") logger.warning("Will log") Custom Format & Structured Data python logger = TimeBasedLogger(fmt='[{level}] {user} {message}') logger.info("User action", extra={'user': 'alice'}) Exception Logging python try: 1 / 0 except ZeroDivisionError: logger.error("An error occurred", exc_info=True) When is This Useful? IoT Devices/Sensors: Prevent log flooding from events that occur every millisecond. Web/API Servers: Summarize frequent status checks or health pings. Background Jobs: Avoid excessive logs in loops or polling routines. Why Use TimeBasedLogger? Traditional loggers emit messages for every event, quickly overwhelming log files in high-traffic environments. By logging on a time-interval basis, TimeBasedLogger ensures logs remain concise, relevant, and easier to analyze, all while remaining highly customizable for professional use. Try it now and keep your Python logs meaningful—even in the noisiest systems!

Share card

Actual performance

1points
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Strong signals: supports · Missing: reddit linkedin, podcasting, created
82%82% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Product HuntOn track for Day 1 leaderboard · Strong signals: user, context, using · Missing: mac, agents, macos
71%71% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
AppSumoStrong fit for a featured deal · Missing: plus, platform, intuitive
53%53% predicted probability of success on AppSumo, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Missing: mobile apps, ios, personal
34%34% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: io · Missing: https docs, excited, just released
25%25% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
14%14% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Pr
Processing Nginx Logs with Python67%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Processing Nginx Logs with Python

Hacker News3
Me
Measuring Time in Python48%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Measuring Time in Python

Hacker News2
Ho
How to Write better Python logs with structlog48%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

How to Write better Python logs with structlog

Hacker News3
En
Encrypting all your logs with logrotate and Peacemakr31%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Encrypting all your logs with logrotate and Peacemakr

Hacker News3
Py
Pyrtls, rustls-based modern TLS for Python56%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Pyrtls, rustls-based modern TLS for Python

Hacker News22
Fi
File-based cache for slow Python functions54%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

File-based cache for slow Python functions

Hacker News73
Pr
Propertime – an attempt at proper time management in Python52%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Propertime – an attempt at proper time management in Python

Hacker News3
A
A tiny python app for viewing Twilio SMS Logs46%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A tiny python app for viewing Twilio SMS Logs

Hacker News1
Cu
CustomStringParser ( Python)54%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

CustomStringParser ( Python)

Hacker News1
Do
Do/While in Python55%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Do/While in Python

Hacker News4