PLogger: A Python logging utility for CSV files with intelligent, metric-based rotation strategies to preserve significant data.
Project description
PLogger: An Intelligent Logger for Preserving What Matters Most
PLogger is a universal Python logger designed for collecting and analyzing performance metrics, experimental results, or any other structured data. Its main feature is intelligent rotation strategies that allow you to preserve the most unique and interesting records (outliers) while removing redundant data.
Unlike standard loggers that simply delete old entries, PLogger analyzes the data and retains those that stand out most from the rest.
Key Features
- Intelligent Rotation: Built-in strategies (
by_metric,by_group_metric) to preserve the most significant data when the log limit is reached. - Thread-Safety: Secure logging from multiple threads without the risk of data corruption.
- Ease of Use: A concise API for quick integration into any project.
- CSV Logging: Data is stored in a universal and easily readable CSV format.
- Zero Configuration: Automatic creation of log directories and files.
Installation
pip install plogger
(Note: After you publish the package to PyPI)
Basic Usage
from pathlib import Path
from plogger import PLogger
# Initialize the logger
# Retain up to 100 entries, then remove the "least interesting" based on 'latency_ms' metric
logger = PLogger(
log_path=Path("performance_logs.csv"),
header=["request_id", "latency_ms", "status_code"],
max_entries=100,
rotation_strategy='by_metric',
metric_column='latency_ms'
)
# Log regular requests
logger.log({"request_id": "abc-123", "latency_ms": 52, "status_code": 200})
logger.log({"request_id": "def-456", "latency_ms": 55, "status_code": 200})
# ...after many entries...
# Log an unusually long request.
# Thanks to the 'by_metric' strategy, this record is highly likely
# to be preserved in the log even after rotation.
logger.log({"request_id": "xyz-789", "latency_ms": 5300, "status_code": 500})
Rotation Strategies
fifo: Standard "first-in, first-out" strategy. Removes the oldest entry.by_metric: Finds a pair of entries with the smallest difference in a numerical metric (metric_column) and removes the older one from that pair. Ideal for preserving outliers and unique values.by_group_metric: First finds the largest group of entries (bygroup_column), and then applies theby_metriclogic within that group. Useful when you need to analyze anomalies within the context of a specific category.
License
The project is distributed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 chu4hel_plogger-0.1.0.tar.gz.
File metadata
- Download URL: chu4hel_plogger-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62ea6aa1f69f9e0d4af7aee5cfb5f6d3bf4a5e926751cc43c64cdda6fefd5a6a
|
|
| MD5 |
35de28a1f4bb8495949edf8bcc67209f
|
|
| BLAKE2b-256 |
5eefb3d3e5d961662ebca9d4dfca4cfd39415cb0dc86d00b60e259a38aab5e6a
|
File details
Details for the file chu4hel_plogger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chu4hel_plogger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9dfb861bdb36339138424fb9e6a37571305c24d70acd1bec441cfa06b2406da
|
|
| MD5 |
e58cc5d0e62ea4c93035ed82f31a1320
|
|
| BLAKE2b-256 |
fc24e6582dcb3467237ad3c591170d3e0776588491ff078dfbf6127a9996cddf
|