diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 00000000..bff29e6e --- /dev/null +++ b/.cargo/config @@ -0,0 +1,2 @@ +[build] +rustflags = ["--cfg", "tokio_unstable"] diff --git a/Cargo.toml b/Cargo.toml index c5e34e02..589c97b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,8 @@ remote = { path = "./protocol/remote", optional = true } raw = { path = "./protocol/raw", optional = true } obfs = { path = "./protocol/obfs", optional = true } +console-subscriber = { git = "https://github.com/tokio-rs/console", rev = "b345084b203af2a4ceb4b9e6b3840cb7fe5667f9", optional = true } + [dev-dependencies] rusty-hook = "0.11.0" @@ -44,6 +46,7 @@ default = [ "api_server", "translate", "ss", "trojan", "remote", "obfs" ] translate = [] api_server = [ "warp", "dirs" ] local_log = [ "rabbit-digger/local_log" ] +console = ["console-subscriber"] [workspace] members = [ diff --git a/src/main.rs b/src/main.rs index d89bd766..cdf419b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,13 +116,28 @@ async fn real_main(args: Args) -> Result<()> { #[paw::main] #[tokio::main] async fn main(args: Args) -> Result<()> { + use tracing_subscriber::{layer::SubscriberExt, prelude::*, EnvFilter}; if std::env::var_os("RUST_LOG").is_none() { std::env::set_var( "RUST_LOG", "rabbit_digger=trace,rabbit_digger_pro=trace,rd_std=trace,raw=trace", ) } - tracing_subscriber::fmt::init(); + #[cfg(feature = "console")] + let (layer, server) = console_subscriber::TasksLayer::new(); + let filter = EnvFilter::from_default_env(); + #[cfg(feature = "console")] + let filter = filter.add_directive("tokio=trace".parse()?); + + let t = tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer()) + .with(filter); + #[cfg(feature = "console")] + let t = t.with(layer); + t.init(); + + #[cfg(feature = "console")] + tokio::spawn(server.serve()); match &args.cmd { Some(Command::GenerateSchema { path }) => {