tinystructlog - Context-Aware Loggingο
Welcome to tinystructlog, a minimalistic context-aware structured logging library for Python.
Overviewο
tinystructlog makes it effortless to add contextual information to your logs. Perfect for multi-tenant applications, microservices, async workers, and any application where you need to track request IDs, user IDs, or other contextual data across your application.
Key Featuresο
π― Context-Aware: Automatically inject contextual information into all log messages
π Thread & Async Safe: Built on Pythonβs
contextvarsfor perfect isolationπ¨ Colored Output: Beautiful ANSI-colored terminal output for better readability
β‘ Zero Dependencies: No runtime dependencies - just pure Python
π¦ Minimal & Focused: Does one thing well - context-aware logging
π§ Zero Configuration: Sensible defaults, works out of the box
π‘ Type Hints: Full type hint support for better IDE experience
Quick Exampleο
from tinystructlog import get_logger, set_log_context
log = get_logger(__name__)
# Log without context
log.info("Application started")
# Set context - will be included in all subsequent logs
set_log_context(user_id="12345", request_id="abc-def")
log.info("Processing request")
# Output: [2024-01-17 10:30:45] [INFO] [main:10] [request_id=abc-def user_id=12345] Processing request
Installationο
Install via pip:
pip install tinystructlog
Python 3.11+ is required.