Skip to content

Commit

Permalink
refactor: move trace configuration to infra crate
Browse files Browse the repository at this point in the history
commit-id:cf4a80d3
  • Loading branch information
lev-starkware committed Jul 8, 2024
1 parent 4269f5b commit 588108f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/mempool_infra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[dev-dependencies]
assert_matches.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/mempool_infra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod component_client;
pub mod component_definitions;
pub mod component_runner;
pub mod component_server;
pub mod trace_util;
15 changes: 15 additions & 0 deletions crates/mempool_infra/src/trace_util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use tracing::metadata::LevelFilter;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO;

pub fn configure_tracing() {
let fmt_layer = fmt::layer().compact().with_target(false);
let level_filter_layer =
EnvFilter::builder().with_default_directive(DEFAULT_LEVEL.into()).from_env_lossy();

// This sets a single subscriber to all of the threads. We may want to implement different
// subscriber for some threads and use set_global_default instead of init.
tracing_subscriber::registry().with(fmt_layer).with(level_filter_layer).init();
}
1 change: 0 additions & 1 deletion crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ starknet_mempool = { path = "../mempool", version = "0.0" }
starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" }
starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
tokio.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing.workspace = true
validator.workspace = true

Expand Down
16 changes: 1 addition & 15 deletions crates/mempool_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@ use std::process::exit;

use papyrus_config::validators::config_validate;
use papyrus_config::ConfigError;
use starknet_mempool_infra::trace_util::configure_tracing;
use starknet_mempool_node::communication::{create_node_channels, create_node_clients};
use starknet_mempool_node::components::create_components;
use starknet_mempool_node::config::MempoolNodeConfig;
use starknet_mempool_node::servers::{create_servers, run_server_components};
use tracing::metadata::LevelFilter;
use tracing::{error, info};
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO;

fn configure_tracing() {
let fmt_layer = fmt::layer().compact().with_target(false);
let level_filter_layer =
EnvFilter::builder().with_default_directive(DEFAULT_LEVEL.into()).from_env_lossy();

// This sets a single subscriber to all of the threads. We may want to implement different
// subscriber for some threads and use set_global_default instead of init.
tracing_subscriber::registry().with(fmt_layer).with(level_filter_layer).init();
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down

0 comments on commit 588108f

Please sign in to comment.