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
delta_logger-0.1.0.tar.gz
(3.9 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 delta_logger-0.1.0.tar.gz.
File metadata
- Download URL: delta_logger-0.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
291d723d4d22a9762c425513e31198bee9ec522d033f2fef60b71dd5118f3a27
|
|
| MD5 |
aff6a4774d026ffd1d9d9ab2b03d136a
|
|
| BLAKE2b-256 |
e9dc6f6243248020cf46596e3ae6fb267fb14da3d159f35265ca915b720ebe29
|
File details
Details for the file delta_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: delta_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 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 |
597c8ef1a19e27d1418c79fc0036c3c3b671ce93cbdad67a113cf6118760e831
|
|
| MD5 |
ef1c898cc502be0e8509fd07c7fa16f1
|
|
| BLAKE2b-256 |
121797732c551d5dc9c33c327436c66d0e7c622c34acfe7e845fb137dbf0b0d4
|