LLM-optimized logging library for Python applications
Project description
LMLog
LLM-optimized structured logging for Python applications
LMLog provides structured logging specifically designed for LLM consumption, enabling better debugging assistance across any Python codebase. Instead of human-readable log messages, it captures debugging context that helps LLMs understand and troubleshoot your code effectively.
Features
- 10-80x Faster - Uses msgspec and orjson for blazing fast serialization
- Universal Event Types - Works with any Python application (web, CLI, data pipelines, etc.)
- Structured JSON Output - Machine-readable logs optimized for LLM analysis
- Async Support - Full async/await compatibility with context managers
- Modern Python 3.11+ - Leverages latest performance improvements
- Thread Safe - Concurrent logging with buffering support
- Memory Efficient - Uses generators, deques, and preallocated buffers
- Decorators - Automatic logging with @lru_cache optimization
- Context Tracking - Operation correlation and state change monitoring
Quick Start
from lmlog import OptimizedLLMLogger
# High-performance logger with modern optimizations
logger = OptimizedLLMLogger("debug.jsonl", encoder="msgspec")
logger.add_global_context(app="my_app", version="1.0")
# Log structured events
logger.log_event(
event_type="data_anomaly",
entity_type="user",
entity_id="user_123",
context={"expected": 100, "actual": 0}
)
# Track state changes
logger.log_state_change(
entity_type="order",
entity_id="order_456",
field="status",
before="pending",
after="completed",
trigger="payment_received"
)
# Monitor performance
logger.log_performance_issue(
operation="database_query",
duration_ms=5000,
threshold_ms=1000
)
Decorators
from lmlog import capture_errors, log_performance, log_calls
@capture_errors(logger)
@log_performance(logger, threshold_ms=2000)
@log_calls(logger)
async def process_data(data):
# Your code here
return result
Context Managers
# Sync operations
with logger.operation_context("user_registration") as op_id:
validate_user(user_data)
create_account(user_data)
# Async operations
async with logger.aoperation_context("batch_processing") as op_id:
await process_batch(items)
Event Types
LMLog captures universal debugging patterns:
data_anomaly- Unexpected values, validation failuresperformance_issue- Slow operations, resource problemsbusiness_rule_violation- Logic constraints violatedintegration_failure- External API/service errorsstate_change- Entity modificationsauthentication_issue- Auth/permission problemsuser_behavior_anomaly- Security-relevant patterns
Configuration
from lmlog import LLMLogger, LLMLoggerConfig
# From file
config = LLMLoggerConfig.from_file("logging.json")
logger = LLMLogger(**config.to_dict())
# Programmatic
config = LLMLoggerConfig(
output="app.jsonl",
buffer_size=100,
global_context={"service": "api"}
)
logger = LLMLogger(**config.to_dict())
Performance
LMLog uses cutting-edge optimizations:
- msgspec - Up to 80x faster than pydantic for serialization
- orjson - 2-3x faster JSON encoding than stdlib
- functools.lru_cache - Caches repeated operations
- Preallocated buffers - Avoids memory reallocation
- Method caching - Eliminates attribute lookups in hot paths
- Batch operations - Efficient bulk event processing
Installation
pip install lmlog
Requirements
- Python 3.11+ (leverages latest performance features)
- msgspec (high-performance serialization)
- orjson (fast JSON encoding)
Development
git clone https://github.com/username/lmlog.git
cd lmlog
make install-dev
make test
make lint
License
MIT License - see LICENSE file for details.
Why LMLog?
Traditional logs are designed for humans. LMLog is designed for LLMs to help you debug faster:
Traditional Logging:
2025-06-25 10:30:15 ERROR: Payment failed for user 123
LMLog Output:
{
"event_type": "business_rule_violation",
"timestamp": "2025-06-25T10:30:15Z",
"entity": {"type": "user", "id": "123"},
"violation": {
"rule": "payment_limit_exceeded",
"expected": 1000,
"actual": 1500
},
"context": {"payment_method": "credit_card", "retry_count": 3},
"source": {"file": "payment.py", "line": 45, "function": "process_payment"}
}
The structured format enables LLMs to quickly understand the problem, suggest solutions, and identify patterns across your application.
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 lmlog-0.2.1.tar.gz.
File metadata
- Download URL: lmlog-0.2.1.tar.gz
- Upload date:
- Size: 52.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d3892f9acf97be03375f10ebc948b05616a181b8a15b7d11e4899565b45dab0
|
|
| MD5 |
c0d88ffd96339641976dacd08ccf6045
|
|
| BLAKE2b-256 |
2545ce6a982af42d5d4cd5e7763560e3047f5b47d04c794a2318f39fb5391ab7
|
Provenance
The following attestation bundles were made for lmlog-0.2.1.tar.gz:
Publisher:
release.yml on HardwareWolf/lmlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmlog-0.2.1.tar.gz -
Subject digest:
3d3892f9acf97be03375f10ebc948b05616a181b8a15b7d11e4899565b45dab0 - Sigstore transparency entry: 253038585
- Sigstore integration time:
-
Permalink:
HardwareWolf/lmlog@fa45bf14ecfe0755ecd345797a70d20554203434 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/HardwareWolf
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fa45bf14ecfe0755ecd345797a70d20554203434 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lmlog-0.2.1-py3-none-any.whl.
File metadata
- Download URL: lmlog-0.2.1-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5af3e5f22b2b7278d176ea79b8eef283d41ab283d10040ffef7ca283f86368c3
|
|
| MD5 |
7439bab1042e570937b942b6a7f207d3
|
|
| BLAKE2b-256 |
703ae07109624aa889d09d36694511ce3c4c30a844a63d6a4bedb15685573d8f
|
Provenance
The following attestation bundles were made for lmlog-0.2.1-py3-none-any.whl:
Publisher:
release.yml on HardwareWolf/lmlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmlog-0.2.1-py3-none-any.whl -
Subject digest:
5af3e5f22b2b7278d176ea79b8eef283d41ab283d10040ffef7ca283f86368c3 - Sigstore transparency entry: 253038589
- Sigstore integration time:
-
Permalink:
HardwareWolf/lmlog@fa45bf14ecfe0755ecd345797a70d20554203434 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/HardwareWolf
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fa45bf14ecfe0755ecd345797a70d20554203434 -
Trigger Event:
push
-
Statement type: