mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
refactor(telemetry): make bunyan as a feature
This commit is contained in:
parent
fe0b153caa
commit
e21e73f0b4
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1754,7 +1754,6 @@ dependencies = [
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-bunyan-formatter",
|
||||
"tracing-log 0.2.0",
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
]
|
||||
|
||||
@ -9,7 +9,7 @@ edition = "2024"
|
||||
async-trait = "0.1"
|
||||
color-eyre = "0.6"
|
||||
dotenv = "0.15"
|
||||
futures = "0.3.31"
|
||||
futures = "0.3"
|
||||
infer = "0.19"
|
||||
rand = "0.9"
|
||||
regex = "1.11"
|
||||
@ -26,11 +26,13 @@ tokio = { version = "1", features = [
|
||||
] }
|
||||
tracing = "0.1"
|
||||
tracing-appender = "0.2"
|
||||
tracing-bunyan-formatter = { version = "0.3", default-features = false }
|
||||
tracing-log = "0.2.0"
|
||||
tracing-bunyan-formatter = { version = "0.3", default-features = false, optional = true }
|
||||
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
|
||||
url = "2.5"
|
||||
|
||||
[features]
|
||||
bunyan = ["tracing-bunyan-formatter"]
|
||||
|
||||
[lints.clippy]
|
||||
pedantic = "warn"
|
||||
nursery = "warn"
|
||||
|
||||
@ -1,14 +1,31 @@
|
||||
#[cfg(feature = "bunyan")]
|
||||
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
||||
use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
/// Initialise tracing with bunyan-style JSON output.
|
||||
#[cfg(feature = "bunyan")]
|
||||
pub fn setup_logger() {
|
||||
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into());
|
||||
let env_filter = create_env_filter();
|
||||
let formatter = BunyanFormattingLayer::new("tg-relay-rs".into(), std::io::stdout);
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(env_filter)
|
||||
.with(JsonStorageLayer)
|
||||
.with(formatter)
|
||||
.init();
|
||||
.with(JsonStorageLayer)
|
||||
.init()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bunyan"))]
|
||||
pub fn setup_logger() {
|
||||
let env_filter = create_env_filter();
|
||||
let formatter = tracing_subscriber::fmt::Layer::default();
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(env_filter)
|
||||
.with(formatter)
|
||||
.init()
|
||||
}
|
||||
|
||||
fn create_env_filter() -> EnvFilter {
|
||||
EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into())
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user