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:
nonesizetime
- Optional compression for rotated files:
.zstwhen zstd is available.gzfallback when zstd is unavailable
- Rotation retention via
backup_count(0..10) - Optional
silentmode 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 integerlog_file: Optional output file path; when omitted, logs go to consolerotation: Rotation strategy (none,size,time)max_bytes: File size threshold forsizerotationwhen: Time unit fortimerotation (passed toTimedRotatingFileHandler)interval: Rotation interval fortimerotationbackup_count: Number of rotated files to keep (0..10)compress: Compress rotated files; requireslog_filesilent: Disable console fallback and stop propagation to parent/root loggers
Validation rules
compress=Truerequireslog_filebackup_countmust be between0and10(inclusive)backup_count=0disables 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.propagateis set toFalse.
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)
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df9fea1991dfb593788a2a3659c01aa5f15ceac21f79dcf335a8c91b554c21db
|
|
| MD5 |
b9d7c40f3e463642f5900f1bb9db1250
|
|
| BLAKE2b-256 |
667ee02c1b9c1294bed5a6844b41263b4f4afa9d7e668d469a02eacfd9faa584
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7658bc75f9145faa3a6ba48a95f9b56f479d5667da847c9e07800a7d0e87ba4
|
|
| MD5 |
5e853f0e549685fdcc814c8b5c099293
|
|
| BLAKE2b-256 |
0bcf0f0dabd6b4bb31224829c22edbd3731415379341de228d9f553f60eb76c3
|