Skip to content

Commit

Permalink
fix: ensure log crate output is shown with tracing (#2477)
Browse files Browse the repository at this point in the history
fix: ensure log crate is taken in account by tracing
  • Loading branch information
glihm authored Sep 25, 2024
1 parent 6eb2b6d commit 1e8ad6f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ tokio = { version = "1.39.2", features = [ "full" ] }
toml = "0.8"
tower = "0.4.13"
tower-http = "0.4.4"
tracing = "0.1.34"
tracing = { version = "0.1.38", features = [ "log" ], default-features = false }
tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3.16", features = [ "env-filter", "json" ] }
url = { version = "2.4.0", features = [ "serde" ] }
walkdir = "2.5.0"
Expand Down
1 change: 1 addition & 0 deletions bin/katana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ serde_json.workspace = true
shellexpand = "3.1.0"
tokio.workspace = true
tracing.workspace = true
tracing-log.workspace = true
tracing-subscriber.workspace = true
url.workspace = true

Expand Down
3 changes: 3 additions & 0 deletions bin/katana/src/cli/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use katana_primitives::genesis::Genesis;
use katana_rpc::config::ServerConfig;
use katana_rpc_api::ApiKind;
use tracing::{info, Subscriber};
use tracing_log::LogTracer;
use tracing_subscriber::{fmt, EnvFilter};
use url::Url;

Expand Down Expand Up @@ -250,6 +251,8 @@ impl NodeArgs {
katana_core=trace,blockifier=off,jsonrpsee_server=off,\
hyper=off,messaging=debug,node=error";

LogTracer::init()?;

let builder = fmt::Subscriber::builder().with_env_filter(
EnvFilter::try_from_default_env().or(EnvFilter::try_new(DEFAULT_LOG_FILTER))?,
);
Expand Down
1 change: 1 addition & 0 deletions bin/saya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ serde_json.workspace = true
starknet.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-log.workspace = true
tracing-subscriber.workspace = true
url.workspace = true

Expand Down
5 changes: 4 additions & 1 deletion bin/saya/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use starknet::core::utils::cairo_short_string_to_felt;
use starknet::signers::SigningKey;
use starknet_account::StarknetAccountOptions;
use tracing::Subscriber;
use tracing_log::LogTracer;
use tracing_subscriber::{fmt, EnvFilter};
use url::Url;

Expand Down Expand Up @@ -74,7 +75,9 @@ pub struct SayaArgs {

impl SayaArgs {
pub fn init_logging(&self) -> Result<(), Box<dyn std::error::Error>> {
const DEFAULT_LOG_FILTER: &str = "info,saya::core=trace,blockchain=trace,provider=trace";
const DEFAULT_LOG_FILTER: &str = "info,saya::core=trace,blockchain=off,provider=off";

LogTracer::init()?;

let builder = fmt::Subscriber::builder().with_env_filter(
EnvFilter::try_from_default_env().or(EnvFilter::try_new(DEFAULT_LOG_FILTER))?,
Expand Down
2 changes: 1 addition & 1 deletion bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ starknet-crypto.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-log = "0.1.3"
tracing-log.workspace = true
tracing-subscriber.workspace = true
url.workspace = true

Expand Down
18 changes: 10 additions & 8 deletions bin/sozo/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use scarb::compiler::Profile;
use scarb_ui::Verbosity;
use smol_str::SmolStr;
use tracing::level_filters::LevelFilter;
use tracing::Subscriber;
use tracing_log::AsTrace;
use tracing_subscriber::{fmt, EnvFilter};
use tracing_log::{AsTrace, LogTracer};
use tracing_subscriber::FmtSubscriber;

use crate::commands::Commands;
use crate::utils::generate_version;
Expand Down Expand Up @@ -53,13 +52,16 @@ impl SozoArgs {
}

pub fn init_logging(&self) -> Result<(), Box<dyn std::error::Error>> {
const DEFAULT_LOG_FILTER: &str = "info,hyper=off,scarb=off";
const DEFAULT_LOG_FILTER: &str = "info,hyper=off,scarb=off,salsa=off";

let builder = fmt::Subscriber::builder().with_env_filter(
EnvFilter::try_from_default_env().or(EnvFilter::try_new(DEFAULT_LOG_FILTER))?,
);
LogTracer::init()?;

let subscriber: Box<dyn Subscriber + Send + Sync> = Box::new(builder.finish());
let subscriber = FmtSubscriber::builder()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(DEFAULT_LOG_FILTER)),
)
.finish();

Ok(tracing::subscriber::set_global_default(subscriber)?)
}
Expand Down

0 comments on commit 1e8ad6f

Please sign in to comment.