Skip to content

Commit

Permalink
Merge pull request #179 from eqlabs/krisztian/tokio-console
Browse files Browse the repository at this point in the history
feat(pathfinder): add tokio-console non-default feature
  • Loading branch information
kkovaacs authored Mar 9, 2022
2 parents d0ca729 + 0395366 commit 83922d3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
4 changes: 4 additions & 0 deletions crates/pathfinder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ license = "MIT OR Apache-2.0"
name = "pathfinder_lib"
path = "src/lib.rs"

[features]
tokio-console = ["console-subscriber", "tokio/tracing"]

[dependencies]
anyhow = "1.0.44"
async-trait = "0.1.52"
# paritys scale codec locks us here
bitvec = "0.20.4"
bytes = "1.1.0"
clap = "2.33.3"
console-subscriber = { version = "0.1.3", optional = true }
enum-iterator = "0.7.0"
futures = { version = "0.3", default-features = false, features = ["std"] }
hex = "0.4.3"
Expand Down
36 changes: 31 additions & 5 deletions crates/pathfinder/src/bin/pathfinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ async fn main() -> anyhow::Result<()> {
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "info");
}
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_target(false)
.compact()
.init();

setup_tracing();

let config =
config::Configuration::parse_cmd_line_and_cfg_file().context("Parsing configuration")?;
Expand Down Expand Up @@ -93,3 +90,32 @@ async fn ethereum_transport(config: EthereumConfig) -> anyhow::Result<Web3<Http>

Ok(Web3::new(client))
}

#[cfg(feature = "tokio-console")]
fn setup_tracing() {
use tracing_subscriber::prelude::*;

// EnvFilter isn't really a Filter, so this we need this ugly workaround for filtering with it.
// See https://github.com/tokio-rs/tracing/issues/1868 for more details.
let env_filter = Arc::new(tracing_subscriber::EnvFilter::from_default_env());
let fmt_layer = tracing_subscriber::fmt::layer()
.with_target(false)
.compact()
.with_filter(tracing_subscriber::filter::dynamic_filter_fn(
move |m, c| env_filter.enabled(m, c.clone()),
));
let console_layer = console_subscriber::spawn();
tracing_subscriber::registry()
.with(fmt_layer)
.with(console_layer)
.init();
}

#[cfg(not(feature = "tokio-console"))]
fn setup_tracing() {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_target(false)
.compact()
.init();
}

0 comments on commit 83922d3

Please sign in to comment.