Skip to content

Commit

Permalink
feat: add console-subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed Jun 23, 2021
1 parent 7071019 commit 2bf5e02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg", "tokio_unstable"]
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 = [
Expand Down
17 changes: 16 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 2bf5e02

Please sign in to comment.