A Python library for logging messages to JSON files with rotation and validation.
Project description
delta_logger
A Python library for logging messages to JSON files with rotation and validation.
Installation
pip install dict_delta_logger
Usage
from delta_logger import DeltaLogger, LogMessageModel
from pydantic import BaseModel, ValidationError
logger = DeltaLogger("example_log", log_dir="logs", max_files=5)
for i in range(10):
message = {
"key1": f"Value {i}",
"key2": i,
"key3": {f"nested_key_{i:3d}": f"Nested value {i}"}
}
# directly log the dict message
# delta_logger.log(message)
class LogMessageModel(BaseModel):
key1: str
key2: int
key3: Dict[str, Any]
# Validate the message using the Pydantic model
try:
validated_message = LogMessageModel(**message)
# Log the validated message
delta_logger.log(validated_message.dict())
except ValidationError as e:
print(f"Validation error: {e}")
merged_logs = delta_logger.merge_logs()
print(json.dumps(merged_logs, indent=4))
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 dict_delta_logger-0.1.0.tar.gz.
File metadata
- Download URL: dict_delta_logger-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a247e417194b72713b85784efa2430566f3f7199e1c591077547f8d824f6365e
|
|
| MD5 |
43907705a98880fc159ba6a41b98f705
|
|
| BLAKE2b-256 |
c5fb10f97c68e1d94799266076f3e9373a47c96c362fa77f125e4cdda77b2ab5
|
File details
Details for the file dict_delta_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dict_delta_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a61af696a45070b60f47d5112e53f28c8bcb00a6116fad5f3d4f6c756f92ee1
|
|
| MD5 |
7a00990baa4530ed8be3e0b672ed5900
|
|
| BLAKE2b-256 |
0ef4fc2e889a117928b0e1180a4d713999746be2e844a4dbdc7124cd55545694
|