Cosmian Logger
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:
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 (optional)no_log_to_stdout: Disable logging to stdoutlog_to_syslog: Enable logging to system logrust_log: Log level configuration
In Tests
The log_init function is safe to use in tests:
Re-exports
The logger crate re-exports common tracing utilities:
use ;