MicroLog is a thread-safe, asynchronous Python logging library designed for production environments. It provides distributed tracing support, high performance, and ease of use.
- Asynchronous Logging - Non-blocking, queue-based background processing
- Distributed Tracing - Built-in support for
trace_id,span_id,parent_span_id - Multiple Formatters - JSON, Pretty (colored), and Compact formats
- File Rotation - Size-based rotation with gzip compression
- Email Notifications - SMTP handler with rate limiting
- Thread-Safe - Safe for concurrent operations
- High Performance - 47,000+ logs per second
- Production-Ready - Validated with 159 tests
pip install vi-microlog# Clone the repository
git clone https://github.com/vidinsight-labs/MicroLog.git
cd MicroLog
# Install in development mode
pip install -e .
# Or use directly (add src directory to PYTHONPATH)
export PYTHONPATH=$(pwd)/src:$PYTHONPATHfrom microlog import setup_logger, trace
import logging
# Create logger
logger = setup_logger("myapp", level=logging.INFO)
# Simple logging
logger.info("Application started")
# With trace context
with trace(trace_id="req-123"):
logger.info("Processing request")from microlog import setup_console_logger
logger = setup_console_logger("myapp", service_name="api-service", use_colors=True)
logger.info("Request processed", extra={"user_id": "123", "duration_ms": 45})from microlog import setup_file_logger
logger = setup_file_logger(
name="myapp",
filename="app.log",
format_type="json",
max_bytes=10 * 1024 * 1024, # 10MB
backup_count=5
)
logger.info("Event occurred", extra={"event_type": "user_action"})from microlog import setup_logger, trace
logger = setup_logger("myapp")
# Automatic trace context
with trace(correlation_id="req-123") as ctx:
logger.info("Request received")
logger.info("Processing", extra={"trace_id": ctx.trace_id})from microlog import setup_logger, with_trace
logger = setup_logger("myapp")
@with_trace(correlation_id="order-456")
def process_order(order_id: str):
logger.info("Processing order", extra={"order_id": order_id})- Quickstart Guide - Get started in minutes
- Trace Context - Distributed tracing guide
- Formatters - JSON, Pretty, Compact formats
- Handlers - Async handlers and configuration
- File Management - Log rotation and compression
- 159 tests - All tests passing (100%)
- Thread safety - Verified
- Memory stability - No leaks detected
- Performance - 47,000+ logs per second
- Production ready - Tested in API and microservice environments
The project includes 35+ examples organized in 8 categories:
- Quickstart - Minimal examples to get started
- Basic - Console and file logging
- Trace - Distributed tracing patterns
- Advanced - Custom handlers, thread safety
- Web - Flask, FastAPI, Django integrations
- Async - Async/await patterns
- Microservices - Service-to-service tracing
- Production - Production-ready configurations
Browse all examples: examples/README.md
from microlog import setup_logger, trace
logger = setup_logger("api-gateway", service_name="gateway")
def handle_request(request):
with trace(correlation_id=request.headers.get("X-Request-ID")):
logger.info("Request received", extra={"path": request.path})from microlog import setup_file_logger
logger = setup_file_logger(
name="production-app",
filename="/var/log/app.log",
format_type="json",
max_bytes=50 * 1024 * 1024,
backup_count=10,
compress=True
)- Python 3.7+
- No external dependencies (uses only Python standard library)
Contributions are welcome! Please ensure all tests pass before opening an issue or submitting a PR.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For questions, please open an issue or check the documentation.
This project is licensed under the MIT License - see the LICENSE file for details.
- Repository: github.com/vidinsight-labs/MicroLog
- Issues: GitHub Issues
- Documentation: docs/
MicroLog - High-performance asynchronous logging library for Python