| Crates.io | tracing-logger-config |
| lib.rs | tracing-logger-config |
| version | 0.1.2 |
| created_at | 2024-09-09 17:13:53.007809+00 |
| updated_at | 2025-04-15 07:35:26.655101+00 |
| description | Custom logger config for tracing |
| homepage | |
| repository | https://gitlab.com/proximax-latam/celebrities |
| max_upload_size | |
| id | 1369536 |
| size | 74,758 |
tracing_logger_config is a Rust crate designed to simplify logging configuration and tracing setup using OpenTelemetry and the tracing crate. It provides an easy-to-use interface for managing log files, controlling log rotation, and setting up distributed tracing with optional Jaeger backend support.
To use tracing_logger_config in your project, add it to your Cargo.toml:
[dependencies]
tracing_logger_config = "0.1.2"
Here's how to configure logging and tracing in your application:
use tracing_logger_config::{Config, init_tracing, RotationKind, LevelInner, ExporterEndpoint};
fn main() -> anyhow::Result<()> {
let config = Config {
log_path: Some("logs/app.log".into()),
log_error_path: Some("logs/error.log".into()),
rotation: RotationKind::Daily,
level: Some(LevelInner::Info),
exporter_endpoint: Some(ExporterEndpoint {
host: "localhost".to_string(),
port: 6831,
}),
};
let _guard = init_tracing(config.exporter_endpoint.as_ref(), Some(&config))?;
// Your application code here
Ok(())
}
The Config struct is used to specify logging and tracing settings. It allows you to set:
The init_tracing function sets up tracing with OpenTelemetry, including optional Jaeger backend support:
use tracing_logger_config::{init_tracing, Config, ExporterEndpoint};
fn setup_tracing() -> anyhow::Result<()> {
let exporter_endpoint = ExporterEndpoint {
host: "localhost".to_string(),
port: 6831,
};
let config = Config {
log_path: Some("logs/app.log".into()),
level: Some(LevelInner::Debug),
..Default::default()
};
let _guard = init_tracing(Some(&exporter_endpoint), Some(&config))?;
// Tracing is now initialized
Ok(())
}
This crate is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Please open an issue or submit a pull request to contribute to tracing_logger_config.
For more information, see the CONTRIBUTING guidelines.