A module to add logging in json format that an AI could easily understand.
Project description
AI Logger
A Python module for structured logging in a format that's easily parsable by AI systems. It provides comprehensive, context-rich logs to help AI systems understand application behavior.
Features
- JSON-formatted logs optimized for AI consumption
- Automatic capturing of context (filename, line number, function)
- Decorators for easy function and class wrapping
- Support for different event types (model, data, error)
- Simple integration with existing Python logging
Installation
# Install using Poetry
poetry install
Example Usage
The package includes a complete example with Click CLI commands to demonstrate the AI Logger functionality:
# Run all examples
poetry run run-example run-all
# Run just the function example
poetry run run-example run-function --size 200
# Run just the class example
poetry run run-example run-class --initial 10 --operations 8
# Run just the module example
poetry run run-example run-module
Basic Code Usage
from ai_logger.src.utils.ai_logger import AILogger
# Initialize logger
logger = AILogger(
app_name="my_app",
log_file="ai_logs.json",
console_output=True
)
# Log a model event
logger.log_model_event(
model_name="gpt-4",
event_type="inference",
input_tokens=150,
output_tokens=30,
latency_ms=500
)
# Wrap a function with logging
@logger.wrap_function(component="data_processor")
def process_data(data):
# Function code here
return result
# Wrap an entire class
@logger.wrap_class(component="ml_model")
class MyModel:
def predict(self, inputs):
# Method code here
return prediction
Log Structure
Events are stored as JSON objects with the following structure:
{
"event_id": "unique-uuid",
"timestamp": "2023-07-20T14:30:00.123456",
"event_type": "inference",
"component": "model",
"file_name": "/path/to/file.py",
"line_number": 42,
"function_name": "predict",
"model_name": "gpt-4",
"input_tokens": 150,
"output_tokens": 30,
"latency_ms": 500,
"details": {
"app_name": "my_app",
"custom_field": "custom_value"
}
}
License
MIT
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 ai_logger-0.1.0.tar.gz.
File metadata
- Download URL: ai_logger-0.1.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14a0e47f78163b7f4c9455243d3c97110ed20e062ead6120c78bacd9063fb607
|
|
| MD5 |
cdcf54c852584d9a0c48cab5c20f562e
|
|
| BLAKE2b-256 |
dfad7854e21d7a1ae78fc07d531d61c7deae8b64f778567718842449d47a0e7f
|
File details
Details for the file ai_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
363285cdf87b6e0b4cfb47e799f3d758c2f838cbb2850365444d1f0062917415
|
|
| MD5 |
434449532a76605d5367e898dea52dc6
|
|
| BLAKE2b-256 |
79ea009035edd3953fbd29542ad1e20da4654c6bc759cdd7ced7443a0fef06d4
|