Skip to main content

A logger that logs messages based on time intervals, not message count.

Project description

TimeBasedLogger

PyPI version Build Status PyPI downloads License: MIT Python Versions

A Python logger that only logs messages at a specified time interval.


🚀 Production-Grade Features

  • Log Levels: DEBUG, INFO, WARNING, ERROR, CRITICAL, with filtering and convenience methods.
  • Log Formatting: Customizable log message format (default: [{{level}}] {{asctime}} {{message}}).
  • Exception Logging: Log exceptions with stack traces using exc_info=True.
  • Structured/Extra Data: Add extra fields to log records for structured logging.

Project Links

Installation

Install from PyPI:

pip install timebased-logger

Or, just copy timebased_logger.py into your project.

Features

  • Log messages only once per specified interval
  • Limit the number of logs per interval (max_logs_per_interval)
  • Pause and resume logging
  • Custom time function for advanced testing
  • High performance async mode: background logging with batching
  • Thread safety: optional locking for multi-threaded use
  • Log levels, formatting, and exception logging (see below)

Usage

Basic Usage

from timebased_logger import TimeBasedLogger
logger = TimeBasedLogger(interval_seconds=2)
logger.log("Hello")
logger.log("World")  # Will not log if called within 2 seconds

Log Levels and Filtering

logger = TimeBasedLogger(level='WARNING')
logger.info("This will NOT be logged")
logger.warning("This will be logged")
logger.error("This will also be logged")

Convenience Methods

logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.critical("Critical message")

Log Formatting

logger = TimeBasedLogger(fmt='[{level}] {asctime} {message}')
logger.info("Formatted log message")

Exception Logging

try:
    1/0
except ZeroDivisionError:
    logger.error("An error occurred", exc_info=True)

Structured/Extra Data

logger = TimeBasedLogger(fmt='[{level}] {user} {message}')
logger.info("User logged in", extra={'user': 'alice'})

API Documentation

TimeBasedLogger

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timebased_logger-0.1.4.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timebased_logger-0.1.4-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file timebased_logger-0.1.4.tar.gz.

File metadata

  • Download URL: timebased_logger-0.1.4.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for timebased_logger-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2799351d697ff57a55d5dc804f85f1f2e7215f083f3330fe600efc6433505372
MD5 d27dbe208a2c683e29f7c24592b9fbc2
BLAKE2b-256 aa8100d74cf911d0887926d4dd7cb61efec514db2075495c8a3dac1fe27ac9ac

See more details on using hashes here.

File details

Details for the file timebased_logger-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for timebased_logger-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d8596aac10fe6e55a3dcc362deac770cf6c9c5e02c234a0a6d57712d861f79d2
MD5 7462267d9374f45157d3aa4c3505f475
BLAKE2b-256 5d5be843dad3d0cebbc790480e79fe17021cabe9c9494cb9c490ea6213b2c0b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page