Skip to main content

Asynchronous logging with queueing and deduplication

Project description

aqdlog

aqdlog is a lightweight asynchronous logging helper for Python.

Features

  • Non-blocking logging via QueueHandler + QueueListener
  • Duplicate suppression for repeated (level, message) pairs
  • Optional file output with rotation modes:
    • none
    • size
    • time
  • Optional compression for rotated files:
    • .zst when zstd is available
    • .gz fallback when zstd is unavailable
  • Rotation retention via backup_count (0..10)
  • Optional silent mode to disable console fallback and parent/root propagation
  • Graceful logger shutdown via logger.shutdown()

Installation

Using uv:

uv add aqdlog

Or with pip:

pip install aqdlog

Quick start

from aqdlog import logger

log = logger("my_app", level="INFO")
log.info("Service start")
log.warning("Low disk space")
log.warning("Low disk space")  # Duplicate suppressed
log.shutdown()

API

logger(
		name: str,
		level: str | int = "INFO",
		log_file: str | None = None,
		rotation: Literal["none", "size", "time"] = "none",
		max_bytes: int = 5_000_000,
		when: str = "H",
		interval: int = 1,
		backup_count: int = 5,
		compress: bool = False,
		silent: bool = False,
) -> logging.Logger

Parameters

  • name: Logger name (for example __name__)
  • level: Logging level as string or integer
  • log_file: Optional output file path; when omitted, logs go to console
  • rotation: Rotation strategy (none, size, time)
  • max_bytes: File size threshold for size rotation
  • when: Time unit for time rotation (passed to TimedRotatingFileHandler)
  • interval: Rotation interval for time rotation
  • backup_count: Number of rotated files to keep (0..10)
  • compress: Compress rotated files; requires log_file
  • silent: Disable console fallback and stop propagation to parent/root loggers

Validation rules

  • compress=True requires log_file
  • backup_count must be between 0 and 10 (inclusive)
  • backup_count=0 disables rollover

File-only / journald-safe mode

Use silent=True when you want aqdlog to write only to its configured file handlers and not bubble records into parent or root loggers.

from aqdlog import logger

log = logger(
	"my_service",
	log_file="/var/log/my_service.log",
	rotation="size",
	max_bytes=5_000_000,
	backup_count=3,
	compress=True,
	silent=True,
)

log.info("This goes to the log file only")
log.shutdown()

Behavior notes

  • Duplicate suppression is based on (level, message) only.
  • Re-using the same logger name returns the same logger instance.
  • The returned logger includes a shutdown() method that stops the queue listener and closes handlers.
  • When silent=True, logger.propagate is set to False.

Examples

Run the included example script:

uv run python examples/example_script.py

License

MIT

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

aqdlog-2.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

aqdlog-2.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file aqdlog-2.1.0.tar.gz.

File metadata

  • Download URL: aqdlog-2.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aqdlog-2.1.0.tar.gz
Algorithm Hash digest
SHA256 df9fea1991dfb593788a2a3659c01aa5f15ceac21f79dcf335a8c91b554c21db
MD5 b9d7c40f3e463642f5900f1bb9db1250
BLAKE2b-256 667ee02c1b9c1294bed5a6844b41263b4f4afa9d7e668d469a02eacfd9faa584

See more details on using hashes here.

File details

Details for the file aqdlog-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: aqdlog-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aqdlog-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7658bc75f9145faa3a6ba48a95f9b56f479d5667da847c9e07800a7d0e87ba4
MD5 5e853f0e549685fdcc814c8b5c099293
BLAKE2b-256 0bcf0f0dabd6b4bb31224829c22edbd3731415379341de228d9f553f60eb76c3

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