Cosmian Logger
A flexible logging crate that supports both synchronous and asynchronous environments.
Features
full: Enables complete functionality including OpenTelemetry integration, syslog support, and advanced tracing features- Without
full: Provides basic tracing functionality for synchronous applications
⚠️ Important: If you need TelemetryConfig or OpenTelemetry functionality, you must enable the full feature:
[]
= { = "0.5.4", = ["full"] }
Usage
With Full Features
For applications that need OpenTelemetry and advanced features:
[]
= { = "0.5.4", = ["full"] }
use ;
async
Without Full Features (Basic Mode)
For synchronous applications that only need basic logging:
[]
= "0.5.4"
use ;
Logging Macros
The crate provides logging macros that work with or without the full feature:
use ;
// Function name is automatically prefixed to log messages
info!;
debug!;
warn!;
error!;
Features Summary
- Basic logging: stdout, file, and structured logging support
- OpenTelemetry (requires full feature): OTLP tracing and metrics
- Syslog support (requires full feature): System log integration
- Structured logging: Multiple message patterns supported
- ANSI colors: Configurable for interactive vs persistent outputs
A versatile logging and tracing utility for Rust applications that provides:
- Structured logging to stdout
- Syslog integration
- OpenTelemetry support for distributed tracing
- Runtime configuration options
Installation
Add the dependency to your Cargo.toml:
[]
= { = "../path/to/crate/logger" }
Basic Usage
For simple applications, use the log_init function to set up logging:
use log_init;
use ;
The log_init function accepts an optional log level string parameter:
- When
Noneis provided, it falls back to theRUST_LOGenvironment variable - Log levels follow Rust's standard: trace, debug, info, warn, error
Advanced Configuration with OpenTelemetry
For more advanced use cases with OpenTelemetry integration, enable the full feature:
[]
= { = "0.5.4", = ["full"] }
use ;
use span;
use Level;
async
OpenTelemetry Setup
To use OpenTelemetry, start a collector like Jaeger:
Then access the Jaeger UI at http://localhost:16686
Configuration Options
The TracingConfig struct supports:
service_name: Name of your service for tracingotlp: OpenTelemetry configuration (only available withfullfeature)no_log_to_stdout: Disable logging to stdoutlog_to_syslog: Enable logging to system log (only available withfullfeature)rust_log: Log level configurationwith_ansi_colors: Enable ANSI colors in outputlog_to_file: Optional file logging configuration
In Tests
The log_init function is safe to use in tests:
Re-exports
The logger crate re-exports common tracing utilities:
use ;