Arlogi Library Documentation
Version: 0.601.04
Python: 3.13+
License: MIT
Comprehensive documentation for the arlogi logging library - a robust, type-safe, and highly configurable logging solution for Python applications.
Key Features
- ๐ฏ Caller Attribution: Trace log calls across function boundaries using
caller_depthparameter - ๐ Custom TRACE Level: Ultra-detailed logging below DEBUG (level 5)
- ๐จ Rich Console Output: Beautiful colored terminal output with Rich library
- ๐ JSON Logging: Structured JSON logs for machine parsing and analysis
- ๐ง Type-Safe Configuration: Modern
LoggingConfigdataclass for compile-time safety - ๐งช Test-Aware: Automatic test mode detection for seamless pytest integration
- ๐ Multiple Handlers: Console, JSON file, and Syslog support
- ๐๏ธ Modular Handlers: Dedicated JSON-only and syslog-only loggers
Quick Start
from arlogi import LoggingConfig, LoggerFactory, get_logger
# Configure logging using modern architecture
config = LoggingConfig(level="INFO")
LoggerFactory._apply_configuration(config)
# Get logger and log
logger = get_logger(__name__)
logger.info("Hello, Arlogi!", caller_depth=0)
Output:
Documentation Guide
Getting Started
- Installation and basic usage: Get started with arlogi quickly
- Caller Attribution Feature: Learn about the unique
caller_depthparameter
Documentation
๐ User Documentation
-
Installation and setup
- Basic usage patterns
- Configuration options
- Caller attribution guide
- Common patterns
-
Troubleshooting tips
-
Modern
LoggingConfigarchitecture - Global configuration patterns
- Per-module level overrides
- Handler configuration
- Environment-specific setups
-
Dynamic configuration
-
Basic depth usage (
caller_depth=0,caller_depth=1) - Cross-module attribution
- Real-world patterns (web APIs, databases, background jobs)
- Performance considerations
- Testing examples
๐ง Developer Documentation
-
Development setup
- Project structure
- Testing strategies
- Code quality standards
- Release process
-
Contributing guidelines
-
System design overview
- Architecture diagrams (C4 model)
- Design patterns
- Component reference
- Data flow
- Extensibility points
๐ API Reference
-
Public API functions
LoggingConfigreferenceLoggerProtocolinterface- Handler classes
- Log levels
- Type hints
- Examples
Key Features by Category
๐ฏ Caller Attribution
| Feature | Description | Documentation |
|---|---|---|
caller_depth=0 |
Shows current function | Examples |
caller_depth=1 |
Shows immediate caller | Examples |
caller_depth=2+ |
Shows deeper context | Examples |
| Cross-module | Tracks across modules | Examples |
๐ง Configuration
| Feature | Description | Documentation |
|---|---|---|
LoggingConfig |
Type-safe configuration | Config Guide |
| Module Levels | Per-module overrides | Config Guide |
| JSON Logging | Structured output | Config Guide |
| Syslog | System log integration | Config Guide |
๐ Log Levels
| Level | Value | Use Case |
|---|---|---|
TRACE |
5 | Function entry/exit, variable dumps |
DEBUG |
10 | Detailed troubleshooting |
INFO |
20 | General application flow |
WARNING |
30 | Unexpected but recoverable |
ERROR |
40 | Errors that don't stop execution |
CRITICAL |
50 | Serious failures |
๐จ Handlers
| Handler | Purpose | Documentation |
|---|---|---|
ColoredConsoleHandler |
Rich console output | API Reference |
JSONHandler |
JSON to stderr | API Reference |
JSONFileHandler |
JSON to file | API Reference |
ArlogiSyslogHandler |
Syslog output | API Reference |
Quick Reference
Basic Setup
from arlogi import LoggingConfig, LoggerFactory, get_logger
# Configure
config = LoggingConfig(level="INFO")
LoggerFactory._apply_configuration(config)
# Use
logger = get_logger(__name__)
logger.info("Application started", caller_depth=0)
With JSON Logging
config = LoggingConfig(
level="INFO",
json_file_name="logs/app.jsonl"
)
LoggerFactory._apply_configuration(config)
Per-Module Levels
config = LoggingConfig(
level="INFO",
module_levels={
"app.database": "DEBUG",
"app.network": "TRACE"
}
)
LoggerFactory._apply_configuration(config)
Dedicated JSON Logger
from arlogi import get_json_logger, cleanup_json_logger
audit_logger = get_json_logger("audit", "logs/audit.jsonl")
audit_logger.info("User action", user_id=123)
# Clean up when done
cleanup_json_logger("audit")
Performance Notes
- Standard log call: ~0.5ฮผs (no attribution)
- Log with
caller_depth: ~1.5ฮผs (stack frame inspection) - Deep stack (depth=5): ~3ฮผs (multiple frame walks)
For optimal performance, use caller_depth only when needed for debugging or context tracking.
Testing Integration
Arlogi automatically detects test environments (pytest, unittest) and:
- Sets default level to DEBUG (instead of INFO)
- Skips handler setup to prevent double logging
- Works seamlessly with
caplogfixture
No special configuration needed!
Requirements
- Python: 3.13 or higher
- Dependencies:
rich>= 14.2.0 (automatically installed)
Additional Resources
- GitHub Issues: Report bugs and request features
- Changelog: Check project repository for version history
License
MIT License