A lightweight structured logging library with traceability for Python apps.
Project description
loglight
A lightweight structured logging library for Python apps
Minimal config, human-readable JSON logs, and automatic request tracing.
🚀 Features
- 🔹 One-line structured logging:
log.info("message", user_id=..., request_id=...) - 🔹 Built-in request context support (Flask, FastAPI, Django)
- 🔹 Asynchronous background log writer
- 🔹 Standard JSON schema with timestamp, level, metadata
- 🔹 Pluggable sinks (file, stdout, etc.)
- 🔹 Easily trace requests across services using request_id
- 🔹 🔒 Automatic Field Masking: Protect passwords, API keys, credit cards, and sensitive data
- 🔹 Multiple Masking Strategies: FULL, PARTIAL, HASH, NULLIFY, FIRST_LAST
📦 Installation
pip install loglight
# For HTTP handlers (Slack, Webhook, HTTP)
pip install loglight[http]
# For S3 handler
pip install loglight[s3]
🧪 Usage
from loglight import log
log.info("User created", request_id="abc123", user_id="user_1", metadata={"role": "admin"})
🔒 Automatic Field Masking
LogLight automatically masks sensitive fields like passwords, API keys, and credit cards:
from loglight import log
# These fields are automatically masked - no configuration needed!
log.info("User login",
username="john_doe",
password="super_secret", # ✅ Automatically masked
api_key="sk_live_abc123" # ✅ Automatically masked
)
# Output:
# {
# "message": "User login",
# "username": "john_doe",
# "password": "***",
# "api_key": "***"
# }
See Field Masking Guide for advanced configuration and strategies.
With Middleware (FastAPI)
from fastapi import FastAPI
from loglight.middleware.fastapi import LogLightMiddleware
app = FastAPI()
app.add_middleware(LogLightMiddleware)
📁 Log Output Example
{
"timestamp": "2025-06-22T20:02:30.123Z",
"level": "info",
"message": "User created",
"service": "user-service",
"request_id": "abc123",
"user_id": "user_1",
"env": "production",
"metadata": {
"role": "admin"
}
}
🔧 Roadmap
- ✅ Base JSON logger
- ✅ Async queue writer
- ✅ FastAPI + Flask middleware
- ✅ Django middleware
- ✅ S3 / syslog / remote sinks
- ✅ Auto-log decorators
- 🚧 Field redaction
- 🚧 Structured exception tracing
📋 Future Plans
Short Term (v0.2)
- Performance Optimization: Improve async queue handling and reduce latency
- Enhanced Error Handling: Better error messages and debugging for handler failures
- Field Redaction: Automatic masking of sensitive fields (PII, tokens, passwords)
- Structured Exception Tracing: Improved stack trace formatting and context preservation
Medium Term (v0.3-v0.4)
- Distributed Tracing: OpenTelemetry integration for better observability
- Log Aggregation: Built-in support for common log aggregation services (Splunk, DataDog, New Relic)
- Advanced Filtering: Runtime log level and filtering based on conditions
- Custom Formatters: User-defined log formatting strategies
- Rate Limiting: Prevent log spam with intelligent rate limiting
Long Term (v1.0+)
- Performance Benchmarking: Comprehensive performance metrics and optimization
- CLI Tools: Command-line utilities for log analysis and debugging
- Web Dashboard: Simple web interface for log visualization
- Persistence Layer: Built-in log persistence and querying capabilities
- Multi-language Support: SDKs for Node.js, Go, and Java
For more details, see ROADMAP.md
📚 Documentation
- Quick Start
- Installation Guide
- Configuration Guide
- 🔒 Field Masking Guide - NEW! Automatic data protection
- Handler Documentation
- Middleware Integration
- Examples
- Contributing
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 loglight-2.0.0.tar.gz.
File metadata
- Download URL: loglight-2.0.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f37f3f7d1bb3447688d1c8fc2387b270b4e2ae6819c050c80cf28a9df6feb99
|
|
| MD5 |
e82f64033104b9a3be9983c6ed73fcfb
|
|
| BLAKE2b-256 |
1b56273ca91858a4477511ebfc48c2036bbe5b77b324bf13936f9861dda62579
|
File details
Details for the file loglight-2.0.0-py3-none-any.whl.
File metadata
- Download URL: loglight-2.0.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a327d7e4bfba78828de5fe408341701a770b381a48ecd950ed99cd8ee42f9bff
|
|
| MD5 |
ecdabf5bceb5b276c103a4f24da938a6
|
|
| BLAKE2b-256 |
fb1a0738bded6dce2927fabdca0e803fb4e11ae76a26eecc62ecfa4d76e86a54
|