Support tokio-console (#1259)
This commit is contained in:
@@ -37,6 +37,7 @@ tracing-subscriber = { version = "0.3", features = [
|
||||
"time",
|
||||
] }
|
||||
tracing-appender = "0.2.3"
|
||||
console-subscriber = { version = "0.4.1", optional = true }
|
||||
thiserror = "1.0"
|
||||
auto_impl = "1.1.0"
|
||||
crossbeam = "0.8.4"
|
||||
@@ -321,3 +322,4 @@ smoltcp = ["dep:smoltcp", "dep:parking_lot"]
|
||||
socks5 = ["dep:smoltcp"]
|
||||
jemalloc = ["dep:jemallocator", "dep:jemalloc-sys"]
|
||||
jemalloc-prof = ["jemalloc", "dep:jemalloc-ctl", "jemalloc-ctl/stats", "jemalloc-sys/profiling", "jemalloc-sys/stats"]
|
||||
tracing = ["tokio/tracing", "dep:console-subscriber"]
|
||||
|
||||
+19
-5
@@ -2,7 +2,9 @@ use std::{fs::OpenOptions, str::FromStr};
|
||||
|
||||
use anyhow::Context;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};
|
||||
use tracing_subscriber::{
|
||||
layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer, Registry,
|
||||
};
|
||||
|
||||
use crate::common::{config::LoggingConfigLoader, get_logger_timer_rfc3339};
|
||||
|
||||
@@ -102,10 +104,22 @@ pub fn init_logger(
|
||||
.with_writer(std::io::stderr)
|
||||
.with_filter(console_filter);
|
||||
|
||||
tracing_subscriber::Registry::default()
|
||||
.with(console_layer)
|
||||
.with(file_layer)
|
||||
.init();
|
||||
let registry = Registry::default();
|
||||
|
||||
#[cfg(not(feature = "tracing"))]
|
||||
{
|
||||
registry.with(console_layer).with(file_layer).init();
|
||||
}
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
{
|
||||
let console_subscriber_layer = console_subscriber::ConsoleLayer::builder().spawn();
|
||||
registry
|
||||
.with(console_layer)
|
||||
.with(file_layer)
|
||||
.with(console_subscriber_layer)
|
||||
.init();
|
||||
}
|
||||
|
||||
Ok(ret_sender)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user