Skip to main content

Lightweight LLM call logger for OpenAI/Anthropic

Project description

Log and View Python Based LLM Conversations

LLM Logger is a lightweight, local-first tool for inspecting and understanding how your application interacts with large language models like OpenAI GPT-4 or Anthropic Claude.

It helps you:

  • Log and inspect each model call with request/response metadata
  • View differences between turns in a conversation
  • Visualize tool calls, tool responses, and system prompts
  • Compare prompt strategies and debug session behavior

Ideal for developers building agent workflows, chat interfaces, or prompt-based systems.


✨ Features

  • One-line setup – Start logging with a simple wrapper around your OpenAI client
  • 🧠 Automatic session tracking – No manual session IDs or state management required
  • 📀 Local-first logging – Stores structured logs as JSON on your machine
  • 🔍 Rich session insights – Context diffs, tool call/response blocks, and system prompt visibility
  • ⏱️ Latency + metadata capture – Track timing, models, and more with every call
  • 🧹 Framework-agnostic – Works with any Python codebase
  • 🛡️ Privacy-first – Fully offline, no account or server required
  • 🌐 Simple UI – Static frontend served locally; no build step needed for end users
  • 👐 Open source (MIT) – Lightweight, auditable, and easy to extend

📦 Installation

🔹 Installation Options

Option 1: From PyPI (Recommended for most users)

Install the prebuilt package if you just want to use the tool:

pip install llm-logger

Option 2: Local Copy (For direct integration or customization)

Clone the repository and install:

# Clone the repo
git clone https://github.com/akhalsa/llm_debugger.git

# rebuild ui (optional)
cd llm_debugger/llm_logger/front_end
npm install
npx tsc

# Install from the local copy
pip install ./llm_debugger

Note: All installation methods include pre-compiled frontend files. No Node.js or frontend build steps are required for basic usage. The static files (HTML, CSS, JS) are packaged with the library, so the debugger UI works out of the box.

Rebuilding using npm install and npx tsc are required to update the .js files in the static/ folder


🔸 Development Setup (Only for contributors)

If you want to modify the logger or UI code:

  1. Prerequisites:

    • Python ≥ 3.8
    • Node.js & npm (only needed for UI development)
  2. Setup:

    git clone https://github.com/akhalsa/llm_debugger.git
    cd llm_debugger
    
    # Optional: Create a virtual environment
    python3 -m venv venv
    source venv/bin/activate
    
    # Install in development mode
    pip install -e .
    
  3. Frontend Development (only if modifying the UI):

    cd llm_logger/front_end
    npm install
    npx tsc
    

🚀 Usage

1. Wrap Your OpenAI Client

from dotenv import load_dotenv
import openai
import os
from llm_logger import wrap_openai

load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")

openai_client = wrap_openai(
    openai.OpenAI(api_key=api_key),
    logging_account_id="my_project"
)

Then use openai_client as normal:

response = openai_client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What's the capital of France?"}
    ]
)

This writes logs to .llm_logger/logs/.


2. Launch the Log Viewer

Option A: Stand Alone Service Launched From Terminal

This option is ideal for viewing logs from an application running on your local device

# Default port (8000)
llm_logger

# Or specify a custom port
llm_logger -p 8000

Then open in your browser:

http://localhost:8000

Option B: As An Endpoint In Your Python Web Application

You can run the debugger UI alongside your application if you're using a python webapp

Same Process (this example uses FastAPI but you can do something similar from any python webapp framework):

from fastapi import FastAPI
import uvicorn
from llm_logger.log_viewer import create_log_viewer_app
log_viewer_app = create_log_viewer_app(base_url="/debugger")

# Your main application
app = FastAPI()

# Mount the debugger UI at /debugger
app.mount("/debugger", log_viewer_app)

# Run your application
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=5000)

Option C: Docker — Run Your App + the Log Viewer in One Container

You can run both your own app and the log viewer in one container, using any process manager or framework you prefer. (Be sure to expose two ports)

Example Dockerfile:

EXPOSE 5000
EXPOSE 8000

CMD bash -c "\
  uvicorn your_app_module:app --host 0.0.0.0 --port 5000 & \
  uvicorn llm_logger.log_viewer:app --host 0.0.0.0 --port 8000 && wait"

🔁 Not using uvicorn?
Replace uvicorn your_app_module:app --host 0.0.0.0 --port 5000 with whatever launches your app — it could be Flask, Gunicorn, a background service, or anything else.


🛠️ Roadmap Ideas

  • Replay conversation with inline visualization
  • Claude and other model support
  • UI analytics and filters
  • Exportable reports and session sharing
  • Plugin hooks and configuration options

📬 Feedback

Found a bug or have a feature request? Open an issue.


📜 License

MIT

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

llm_logger-0.2.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

llm_logger-0.2.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file llm_logger-0.2.0.tar.gz.

File metadata

  • Download URL: llm_logger-0.2.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for llm_logger-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3349cb996a7a30065fb26dd57ff285c5aebf895878230aa5881b4ac9502f4b6a
MD5 46d02c2cb4ff035a70e906ed49c4556f
BLAKE2b-256 10eec1ba009ee22dcae3a644ce5a1b31f81bf6b1ad0af32b3c8c274198cf3e88

See more details on using hashes here.

File details

Details for the file llm_logger-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: llm_logger-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for llm_logger-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6662f8602ac3a60346213f5bb058a0ca6a27b800525b3723c94b11385f538ca
MD5 51e698e06a0722bdc9481778e99a0e7c
BLAKE2b-256 188d514e3312c592e5fd8a1508a730de703c0512c3c2df4c671e88d1ab2f4b5c

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