Expand description
§DS Common Logger
A high-performance, production-ready logging library for Rust applications that provides structured logging with comprehensive tracing capabilities.
§Overview
This library provides a simple yet powerful interface for initializing global tracing subscribers with support for both JSON and compact output formats, environment-driven filtering, and comprehensive error context capture.
§Features
- Environment-driven filtering - Respects
RUST_LOG
environment variable - Dual output formats - JSON and compact formats via
LOG_FORMAT
environment variable - Error context capture - Automatic span trace capture for better debugging
- Panic logging - Converts panics to structured log events
- Thread-safe initialization - Idempotent initialization safe for concurrent use
- Zero-cost abstractions - Minimal runtime overhead when logging is disabled
§Quick Start
use ds_common_logger_rs_lib::init_tracing;
// Initialize the global tracing subscriber
init_tracing();
// Start logging
tracing::info!("Application started");
tracing::warn!("This is a warning");
tracing::error!("This is an error");
§Configuration
§Log Level Filtering
Control log levels using the RUST_LOG
environment variable:
# Show all logs at info level and above
RUST_LOG=info cargo run
# Show only error logs
RUST_LOG=error cargo run
# Show debug logs for specific modules
RUST_LOG=debug,my_crate::module=info cargo run
§Output Format
Switch between compact and JSON output using the LOG_FORMAT
environment variable:
# Compact format (default)
cargo run
# JSON format
LOG_FORMAT=json cargo run
§Thread Safety
This library is designed to be thread-safe and can be safely called from multiple threads.
The initialization is idempotent, meaning it’s safe to call init_tracing()
multiple times.
§Performance
The library is designed for minimal performance impact:
- Zero-cost when logging is disabled via environment filters
- Efficient string formatting and serialization
- Minimal memory allocations during normal operation
Statics§
- INIT 🔒
Functions§
- init_
tracing - Logger Module