Skip to main content

LLM-optimized structured logging and summarization for large-scale debugging.

Project description

🧠 LLM Logger

LLM Logger is a Python logging framework designed for seamless integration with Large Language Models (LLMs).
It produces structured, LLM-friendly logs that can be easily summarized or reasoned about — even across massive, deeply nested codebases.


🚀 Features

  • 🪵 Structured JSON logs (timestamped, contextual, machine-readable)
  • 🧠 LLM-optimized format with reason, inputs, outputs, and semantic tags
  • 📂 Log grouping (start_group, end_group) and function spans
  • 🔌 Modular LLM backend support via environment variable:
    • Ollama (local models)
    • Groq (LLama, Gemma via API)
    • OpenAI (GPT-3.5 / GPT-4)
  • 📊 Summarization CLI with smart filtering and token-aware chunking
  • 💾 Cache for LLM calls with expiration/cleanup
  • 🧪 Test harness to simulate deeply nested logs

📦 Installation

pip install ailogx

🛠️ Basic Usage

from ailogx.core import LLMLogger

log = LLMLogger("my-service")

log.llm_info("User login started", inputs={"username": "admin"})
log.llm_decision("Using 2FA", reason="high-risk user")
log.llm_error("Login failed", reason="Invalid OTP")

🔁 Function Span

with log.function_span("process_payment", reason="checkout flow"):
    # your logic
    pass

📂 Grouping Logs

log.start_group("req-42", reason="incoming API request")
# your logs here
log.end_group("req-42")

📊 LLM Summarization

🧠 Environment-based Backend Selection

Supports:

  • LLM_LOGGER_BACKEND=ollama (default)
  • LLM_LOGGER_BACKEND=groq
  • LLM_LOGGER_BACKEND=openai

🧾 Example

export LLM_LOGGER_BACKEND=groq  # or 'openai', 'ollama'
export GROQ_API_KEY="your-groq-api-key"
- You must have a Groq account.
- Supported models: gemma3, llama3-70b, etc.

export OPENAI_API_KEY="your-openai-api-key"
- You must have an OpenAI API key.Models like gpt-3.5-turbo, gpt-4, etc. are supported.

For selecting Models : 
| Backend  | Env Var to Set | Example Value         |
|----------|----------------|-----------------------|
| groq     | GROQ_MODEL     | llama-3-70b-8192      |
| openai   | OPENAI_MODEL   | gpt-4o                |
| ollama   | OLLAMA_MODEL   | llama3                |

python -m llm_logger.summarize simulated_logs/deep_nested_logs.jsonl --filter=smart --fast

Or call from Python:

from ailogx.summarizer.summarizer import multi_pass_summarize
from ailogx.backends.registry import get_analyzer
import json

with open("llm_logs.jsonl") as f:
    logs = [json.loads(line) for line in f]

summary = multi_pass_summarize(logs, get_analyzer())
print(summary)

🧪 Test Harness

Generate deep, nested logs for benchmarking:

python ailogx/core.py

Outputs:

  • llm_simulated_logs.jsonl (LLMLogger)
  • standard_simulated_logs.log (Python logging)

🔁 Cache & Optimization

  • ✅ LLM responses cached to .cache/
  • 🧠 Token-aware chunking
  • 🔎 Smart filtering (--filter=smart, --intent="auth errors")
  • --fast mode for shallow summaries before full deep dives

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

ailogx-1.0.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ailogx-1.0.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file ailogx-1.0.0.tar.gz.

File metadata

  • Download URL: ailogx-1.0.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for ailogx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dcd1e774d13dc25d3e90c3e3c867872b25d611f77502b4a3275e4b199be1ad58
MD5 56f99d02e95209bdc1172211496acf1b
BLAKE2b-256 a8593715e75b7da1adc3f4cafe206320cf38d0fa5edb521c55c21aff6f0411d7

See more details on using hashes here.

File details

Details for the file ailogx-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ailogx-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for ailogx-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37256e6f6fd1efc536e12c7b690c7c5ff112308ab3673c2beace21ba9d940ac6
MD5 919f1e6e4fc27302fdfbd86a47c693c8
BLAKE2b-256 68c7a0963982a88e41adf0b6a2ae0eb12b6db639937051286d91bc4f5f57bdae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page