diff --git a/cmd/ethrex/initializers.rs b/cmd/ethrex/initializers.rs index 3ea4cb96957..8ffa69c4c96 100644 --- a/cmd/ethrex/initializers.rs +++ b/cmd/ethrex/initializers.rs @@ -36,7 +36,7 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; use tokio_util::{sync::CancellationToken, task::TaskTracker}; -use tracing::{debug, error, info, warn}; +use tracing::{Level, debug, error, info, warn}; use tracing_subscriber::{ EnvFilter, Layer, Registry, filter::Directive, fmt, layer::SubscriberExt, reload, }; @@ -54,22 +54,23 @@ pub fn init_tracing(opts: &Options) -> reload::Handle { let (filter, filter_handle) = reload::Layer::new(log_filter); - let mut layer = fmt::layer(); + let stdout_is_tty = std::io::stdout().is_terminal(); + let use_color = match opts.log_color { + LogColor::Always => true, + LogColor::Never => false, + LogColor::Auto => stdout_is_tty, + }; - if opts.log_color == LogColor::Never - || (opts.log_color == LogColor::Auto && !std::io::stdout().is_terminal()) - { - layer = layer.with_ansi(false); - } + let include_target = matches!(opts.log_level, Level::DEBUG | Level::TRACE); - let fmt_layer = layer.with_filter(filter); + let fmt_layer = fmt::layer() + .with_target(include_target) + .with_ansi(use_color) + .with_filter(filter); - let subscriber: Box = if opts.metrics_enabled { - let profiling_layer = FunctionProfilingLayer; - Box::new(Registry::default().with(fmt_layer).with(profiling_layer)) - } else { - Box::new(Registry::default().with(fmt_layer)) - }; + let profiling_layer = opts.metrics_enabled.then_some(FunctionProfilingLayer); + + let subscriber = Registry::default().with(fmt_layer).with(profiling_layer); tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index 7fcb3b6303e..e6b65616afb 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -406,7 +406,7 @@ impl Blockchain { } // Store the added storage in the account's storage trie and compute its new root if !update.added_storage.is_empty() { - debug!(count = update.added_storage.len(), "With storages"); + trace!(count = update.added_storage.len(), "Update storages"); let (storage_trie, storage_updates_map) = storage_updates_map .entry(hashed_address_h256) .or_insert_with(|| { diff --git a/crates/networking/p2p/discv4/peer_table.rs b/crates/networking/p2p/discv4/peer_table.rs index 60fa065c6f8..8185055d04e 100644 --- a/crates/networking/p2p/discv4/peer_table.rs +++ b/crates/networking/p2p/discv4/peer_table.rs @@ -582,7 +582,7 @@ impl PeerTableServer { } } // No untried contact found, resetting tried peers. - tracing::info!("Resetting list of tried peers."); + tracing::trace!("Resetting list of tried peers."); self.already_tried_peers.clear(); None } diff --git a/crates/networking/p2p/tx_broadcaster.rs b/crates/networking/p2p/tx_broadcaster.rs index bafbb9626dd..fba9bf693d2 100644 --- a/crates/networking/p2p/tx_broadcaster.rs +++ b/crates/networking/p2p/tx_broadcaster.rs @@ -13,7 +13,7 @@ use spawned_concurrency::{ messages::Unused, tasks::{CastResponse, GenServer, GenServerHandle, send_interval}, }; -use tracing::{debug, error, info}; +use tracing::{debug, error, info, trace}; use crate::{ discv4::peer_table::{PeerTable, PeerTableError}, @@ -184,7 +184,7 @@ impl TxBroadcaster { .get_txs_for_broadcast() .map_err(|_| TxBroadcasterError::Broadcast)?; if txs_to_broadcast.is_empty() { - debug!("No transactions to broadcast"); + trace!("No transactions to broadcast"); return Ok(()); } let peers = self.peer_table.get_peers_with_capabilities().await?; @@ -321,7 +321,7 @@ impl GenServer for TxBroadcaster { ) -> CastResponse { match message { Self::CastMsg::BroadcastTxs => { - debug!(received = "BroadcastTxs"); + trace!(received = "BroadcastTxs"); let _ = self.broadcast_txs().await.inspect_err(|_| { error!("Failed to broadcast transactions");