diff --git a/Cargo.lock b/Cargo.lock index e027317974..d8bb84b6cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1128,6 +1128,7 @@ dependencies = [ "tokio", "tokio-stream", "tokio-util", + "tracing", ] [[package]] @@ -3597,6 +3598,7 @@ dependencies = [ "particle-execution", "particle-protocol", "serde_json", + "tracing", "uuid-utils", ] @@ -3627,6 +3629,7 @@ dependencies = [ "console-subscriber", "log", "tracing", + "tracing-logfmt", "tracing-subscriber", ] @@ -5707,6 +5710,7 @@ dependencies = [ "thiserror", "tokio", "tokio-stream", + "tracing", "uuid", ] @@ -5874,7 +5878,6 @@ dependencies = [ "humantime-serde", "libp2p", "libp2p-metrics", - "log", "num_cpus", "particle-protocol", "peer-metrics", @@ -6078,6 +6081,7 @@ dependencies = [ "thiserror", "tokio", "tokio-stream", + "tracing", "uuid-utils", ] diff --git a/aquamarine/src/aqua_runtime.rs b/aquamarine/src/aqua_runtime.rs index 3f824a8289..bb4bca71b5 100644 --- a/aquamarine/src/aqua_runtime.rs +++ b/aquamarine/src/aqua_runtime.rs @@ -113,7 +113,7 @@ impl AquaRuntime for AVM { match parse_outcome(outcome) { Ok((data, peers, calls)) if !peers.is_empty() || !calls.is_empty() => { #[rustfmt::skip] - log::debug!("Particle {} executed: {} call requests, {} next peers", p.id, calls.len(), peers.len()); + tracing::debug!(particle_id = p.id, "Particle executed: {} call requests, {} next peers", calls.len(), peers.len()); ParticleEffects { next_peers: peers, @@ -122,22 +122,36 @@ impl AquaRuntime for AVM { } } Ok((data, ..)) => { - log::warn!( - "Executed particle {}, next_peer_pks is empty, no call requests. Nothing to do.", - p.id + tracing::warn!( + particle_id = p.id, + "Executed particle, next_peer_pks is empty, no call requests. Nothing to do.", ); if log::max_level() >= LevelFilter::Debug { let data = String::from_utf8_lossy(data.as_slice()); - log::debug!("particle {} next_peer_pks = [], data: {}", p.id, data); + tracing::debug!( + particle_id = p.id, + "particle next_peer_pks = [], data: {}", + data + ); } ParticleEffects::empty(Particle { data, ..p }) } Err(ExecutionError::AquamarineError(err)) => { - log::warn!("Error executing particle {:#?}: {}", p, err); + tracing::warn!( + particle_id = p.id, + "Error executing particle {:#?}: {}", + p, + err + ); ParticleEffects::empty(p) } Err(err @ ExecutionError::InvalidResultField { .. }) => { - log::warn!("Error parsing outcome for particle {:#?}: {}", p, err); + tracing::warn!( + particle_id = p.id, + "Error parsing outcome for particle {:#?}: {}", + p, + err + ); ParticleEffects::empty(p) } } diff --git a/aquamarine/src/particle_data_store.rs b/aquamarine/src/particle_data_store.rs index f5ddf9d8fc..ffa591973d 100644 --- a/aquamarine/src/particle_data_store.rs +++ b/aquamarine/src/particle_data_store.rs @@ -83,7 +83,7 @@ impl DataStore for ParticleDataStore { } fn store_data(&mut self, data: &[u8], particle_id: &str, current_peer_id: &str) -> Result<()> { - log::debug!(target: "particle_reap", "Storing data for particle {}", particle_id); + tracing::debug!(target: "particle_reap", particle_id = particle_id, "Storing data for particle"); let data_path = self.data_file(particle_id, current_peer_id); std::fs::write(&data_path, data).map_err(|err| StoreData(err, data_path))?; @@ -97,7 +97,7 @@ impl DataStore for ParticleDataStore { } fn cleanup_data(&mut self, particle_id: &str, current_peer_id: &str) -> Result<()> { - log::debug!(target: "particle_reap", "Cleaning up particle data for particle {}", particle_id); + tracing::debug!(target: "particle_reap", particle_id = particle_id, "Cleaning up particle data for particle"); remove_file(&self.data_file(particle_id, current_peer_id)).map_err(CleanupData)?; self.vault.cleanup(particle_id)?; diff --git a/aquamarine/src/particle_executor.rs b/aquamarine/src/particle_executor.rs index e5d457d09d..27fda05795 100644 --- a/aquamarine/src/particle_executor.rs +++ b/aquamarine/src/particle_executor.rs @@ -55,7 +55,7 @@ impl ParticleExecutor for RT { let cloned_particle = particle.clone(); let task = tokio::task::Builder::new().name(&format!("Particle {}", particle.id)).spawn_blocking(move || { let now = Instant::now(); - log::info!("Executing particle {}", particle.id); + tracing::info!(particle_id = particle.id, "Executing particle"); let particle_params = ParticleParameters { current_peer_id: Cow::Owned(current_peer_id.to_string()), @@ -71,10 +71,10 @@ impl ParticleExecutor for RT { let stats = InterpretationStats { interpretation_time, new_data_len, success: result.is_ok() }; if let Err(err) = &result { - log::warn!("Error executing particle {:#?}: {}", particle, err) + tracing::warn!(particle_id = particle.id, "Error executing particle {:#?}: {}", particle, err) } else { let len = new_data_len.map(|l| l as i32).unwrap_or(-1); - log::trace!(target: "execution", "Particle {} interpreted in {} [{} bytes => {} bytes]", particle.id, pretty(interpretation_time), particle.data.len(), len); + tracing::trace!(target: "execution", particle_id = particle.id, "Particle interpreted in {} [{} bytes => {} bytes]", pretty(interpretation_time), particle.data.len(), len); } let effects = Self::into_effects(result, particle); @@ -93,9 +93,12 @@ impl ParticleExecutor for RT { Ok(res) => res, Err(err) => { if err.is_cancelled() { - log::warn!("Particle task {} was cancelled", cloned_particle.id); + tracing::warn!( + particle_id = cloned_particle.id, + "Particle task was cancelled" + ); } else { - log::error!("Particle task {} panic", cloned_particle.id); + tracing::error!(particle_id = cloned_particle.id, "Particle task panic"); } let stats = InterpretationStats { interpretation_time: Duration::ZERO, diff --git a/aquamarine/src/particle_functions.rs b/aquamarine/src/particle_functions.rs index 2ba0bb2059..11f7af6e6d 100644 --- a/aquamarine/src/particle_functions.rs +++ b/aquamarine/src/particle_functions.rs @@ -198,11 +198,11 @@ impl Functions { }; if let Err(err) = &result { - log::warn!( - "Failed host call {} ({}) [{}]: {}", + tracing::warn!( + particle_id = particle_id, + "Failed host call {} ({}): {}", log_args, pretty(elapsed), - particle_id, err ) } else { diff --git a/aquamarine/src/plumber.rs b/aquamarine/src/plumber.rs index b67825243f..335373c8e8 100644 --- a/aquamarine/src/plumber.rs +++ b/aquamarine/src/plumber.rs @@ -87,7 +87,7 @@ impl Plumber { let deadline = Deadline::from(&particle); if deadline.is_expired(now_ms()) { - log::info!("Particle {} is expired, ignoring", particle.id); + tracing::info!(particle_id = particle.id, "Particle is expired, ignoring"); self.events .push_back(Err(AquamarineApiError::ParticleExpired { particle_id: particle.id, @@ -196,16 +196,17 @@ impl Plumber { if !actor.is_expired(now) || actor.is_executing() { return true; // keep actor } - log::debug!( + tracing::debug!( target: "particle_reap", - "Reaping particle's actor particle_id={particle_id}, peer_id={peer_id})" + particle_id = particle_id, + "Reaping particle's actor peer_id={peer_id})" ); // cleanup files and dirs after particle processing (vault & prev_data) // TODO: do not pass vm https://github.com/fluencelabs/fluence/issues/1216 if let Err(err) = actor.cleanup(particle_id, &peer_id.to_string(), &mut vm) { - log::warn!( - "Error cleaning up after particle {}: {:?}", - particle_id, + tracing::warn!( + particle_id = particle_id, + "Error cleaning up after particle {:?}", err ) } diff --git a/connection-pool/Cargo.toml b/connection-pool/Cargo.toml index 6cd987c08e..a354cfb38e 100644 --- a/connection-pool/Cargo.toml +++ b/connection-pool/Cargo.toml @@ -13,6 +13,7 @@ libp2p = { workspace = true } futures = { workspace = true } log = { workspace = true } +tracing = { workspace = true } serde = { workspace = true } tokio = { workspace = true } tokio-stream = { workspace = true } diff --git a/connection-pool/src/behaviour.rs b/connection-pool/src/behaviour.rs index c8a7e4cf4c..bd21db46d6 100644 --- a/connection-pool/src/behaviour.rs +++ b/connection-pool/src/behaviour.rs @@ -214,7 +214,7 @@ impl ConnectionPoolBehaviour { outlet.send(SendStatus::Ok).ok(); self.wake(); } else if self.contacts.contains_key(&to.peer_id) { - log::debug!(target: "network", "{}: Sending particle {} to {}", self.peer_id, particle.id, to.peer_id); + tracing::debug!(target: "network",particle_id = particle.id , "{}: Sending particle to {}", self.peer_id, to.peer_id); // Send particle to remote peer self.push_event(ToSwarm::NotifyHandler { peer_id: to.peer_id, @@ -222,9 +222,9 @@ impl ConnectionPoolBehaviour { event: HandlerMessage::OutParticle(particle, CompletionChannel::Oneshot(outlet)), }); } else { - log::warn!( - "Won't send particle {} to contact {}: not connected", - particle.id, + tracing::warn!( + particle_id = particle.id, + "Won't send particle to contact {}: not connected", to.peer_id ); outlet.send(SendStatus::NotConnected).ok(); @@ -562,7 +562,7 @@ impl NetworkBehaviour for ConnectionPoolBehaviour { ) { match event { HandlerMessage::InParticle(particle) => { - log::trace!(target: "network", "{}: received particle {} from {}; queue {}", self.peer_id, particle.id, from, self.queue.len()); + tracing::trace!(target: "network", particle_id = particle.id,"{}: received particle from {}; queue {}", self.peer_id, from, self.queue.len()); self.meter(|m| { m.incoming_particle( &particle.id, @@ -595,9 +595,13 @@ impl NetworkBehaviour for ConnectionPoolBehaviour { if let Some(particle) = self.queue.pop_front() { let particle_id = particle.id.clone(); if let Err(err) = outlet.start_send(particle) { - log::error!("Failed to send particle to outlet: {}", err) + tracing::error!( + particle_id = particle_id, + "Failed to send particle to outlet: {}", + err + ) } else { - log::trace!(target: "execution", "Sent particle {} to execution", particle_id); + tracing::trace!(target: "execution",particle_id = particle_id, "Sent particle to execution"); } } else { break; diff --git a/crates/builtins-deployer/src/builtins_deployer.rs b/crates/builtins-deployer/src/builtins_deployer.rs index cec2e4b541..13200583e5 100644 --- a/crates/builtins-deployer/src/builtins_deployer.rs +++ b/crates/builtins-deployer/src/builtins_deployer.rs @@ -140,7 +140,7 @@ impl BuiltinsDeployer { }; let finished = sent.elapsed(); - log::debug!(target: "execution", "sending particle took {}", pretty(finished)); + tracing::debug!(target: "execution", particle_id = particle.id, "sending particle took {}", pretty(finished)); result } diff --git a/crates/local-vm/Cargo.toml b/crates/local-vm/Cargo.toml index e819e5c533..20bb397f48 100644 --- a/crates/local-vm/Cargo.toml +++ b/crates/local-vm/Cargo.toml @@ -25,3 +25,4 @@ serde_json = { workspace = true } parking_lot = { workspace = true } maplit = { workspace = true } log = { workspace = true } +tracing = { workspace = true } diff --git a/crates/local-vm/src/local_vm.rs b/crates/local-vm/src/local_vm.rs index 09dc083e14..6b0b5d63c3 100644 --- a/crates/local-vm/src/local_vm.rs +++ b/crates/local-vm/src/local_vm.rs @@ -284,7 +284,7 @@ pub fn make_particle( } } - log::info!("Made a particle {}", id); + tracing::info!(particle_id = id, "Made a particle"); Particle { id, diff --git a/crates/log-utils/Cargo.toml b/crates/log-utils/Cargo.toml index 0a2fc15181..9e6a931ae8 100644 --- a/crates/log-utils/Cargo.toml +++ b/crates/log-utils/Cargo.toml @@ -9,3 +9,4 @@ log = { workspace = true } tracing = { workspace = true, features = ["async-await", "log"] } tracing-subscriber.workspace = true console-subscriber = { version = "0.1.8", features = ["parking_lot"] } +tracing-logfmt = "0.3.1" diff --git a/crates/log-utils/src/lib.rs b/crates/log-utils/src/lib.rs index 60984418f7..5f98f0b72d 100644 --- a/crates/log-utils/src/lib.rs +++ b/crates/log-utils/src/lib.rs @@ -56,11 +56,11 @@ pub fn enable_logs() { .add_directive("libp2p_kad::iterlog=info".parse().unwrap()) .add_directive("libp2p_plaintext=info".parse().unwrap()) .add_directive("libp2p_identify::protocol=info".parse().unwrap()) - .add_directive("cranelift_codegen=info".parse().unwrap()) + .add_directive("cranelift_codegen=off".parse().unwrap()) + .add_directive("cranelift_codegen::context=off".parse().unwrap()) .add_directive("wasmer_wasi=info".parse().unwrap()) .add_directive("wasmer_interface_types_fl=info".parse().unwrap()) .add_directive("polling=info".parse().unwrap()) - .add_directive("cranelift_codegen=info".parse().unwrap()) .add_directive("walrus=info".parse().unwrap()), ) .try_init() diff --git a/crates/server-config/Cargo.toml b/crates/server-config/Cargo.toml index 91758e8717..bff41f17d1 100644 --- a/crates/server-config/Cargo.toml +++ b/crates/server-config/Cargo.toml @@ -19,7 +19,6 @@ libp2p-metrics = { workspace = true } serde = { version = "1.0.160", features = ["derive"] } humantime-serde = { workspace = true } serde_json = "1.0.96" -log = { workspace = true } rand = "0.8.5" clap = { version = "4.2.4", features = ["derive", "string"] } bs58 = { workspace = true } diff --git a/crates/server-config/src/args.rs b/crates/server-config/src/args.rs index 0e63957534..8ce009d8e7 100644 --- a/crates/server-config/src/args.rs +++ b/crates/server-config/src/args.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +use crate::LogFormat; use clap::{Args, Parser}; use figment::error::Kind::InvalidType; use figment::value::{Dict, Map, Value}; @@ -107,6 +108,17 @@ impl Serialize for RootKeyPairArgs { } } +#[derive(Args, Debug, Clone, Serialize)] +pub struct LogArgs { + #[arg( + long("log-format"), + id = "LOG_FORMAT", + help_heading = "Node configuration", + display_order = 24 + )] + pub(crate) format: Option, +} + #[derive(Parser, Debug, Serialize, Clone)] pub(crate) struct DerivedArgs { #[arg( @@ -276,6 +288,19 @@ pub(crate) struct DerivedArgs { action = clap::ArgAction::SetTrue )] pub(crate) print_config: Option, + #[arg( + long, + value_parser = clap::value_parser!(bool), + id = "NO_BANNER", + help = "Disable banner", + help_heading = "Node configuration", + display_order = 23, + action = clap::ArgAction::SetTrue + )] + pub(crate) no_banner: Option, + + #[command(flatten)] + log: Option, } impl figment::Provider for DerivedArgs { diff --git a/crates/server-config/src/defaults.rs b/crates/server-config/src/defaults.rs index c682fff4df..c2385a5b84 100644 --- a/crates/server-config/src/defaults.rs +++ b/crates/server-config/src/defaults.rs @@ -182,7 +182,7 @@ pub fn default_management_peer_id() -> PeerId { let public_key = PublicKey::Ed25519(kp.public()); let peer_id = PeerId::from(public_key); - log::warn!( + println!( "New management key generated. ed25519 private key in base64 = {}", base64.encode(kp.secret()), ); diff --git a/crates/server-config/src/kademlia_config.rs b/crates/server-config/src/kademlia_config.rs index ccb3574ce1..89c1ce076e 100644 --- a/crates/server-config/src/kademlia_config.rs +++ b/crates/server-config/src/kademlia_config.rs @@ -62,7 +62,7 @@ impl KademliaConfig { if let Some(replication_factor) = std::num::NonZeroUsize::new(replication_factor) { cfg.set_replication_factor(replication_factor); } else { - log::warn!( + println!( "Invalid config value: replication_factor must be > 0, was {:?}", self.replication_factor ) diff --git a/crates/server-config/src/keys.rs b/crates/server-config/src/keys.rs index b20779e31a..b0f2b8530b 100644 --- a/crates/server-config/src/keys.rs +++ b/crates/server-config/src/keys.rs @@ -24,7 +24,6 @@ use std::{ use base64::{engine::general_purpose::STANDARD as base64, Engine}; use eyre::eyre; use fluence_keypair::{key_pair::KeyFormat, KeyPair}; -use log::info; use fs_utils::create_dirs; @@ -145,7 +144,7 @@ pub fn load_key( ) -> eyre::Result { if !key_path.exists() { return if generate_on_absence { - info!("Generating a new key to {:?}", key_path); + println!("Generating a new key to {:?}", key_path); Ok(create_new_key_pair( &key_path, KeyFormat::from_str(&key_format)?, diff --git a/crates/server-config/src/lib.rs b/crates/server-config/src/lib.rs index cf44accb79..7f3e39fc70 100644 --- a/crates/server-config/src/lib.rs +++ b/crates/server-config/src/lib.rs @@ -48,5 +48,7 @@ pub use bootstrap_config::BootstrapConfig; pub use kademlia_config::KademliaConfig; pub use network_config::NetworkConfig; pub use node_config::{NodeConfig, TransportConfig}; +pub use resolved_config::LogConfig; +pub use resolved_config::LogFormat; pub use resolved_config::{ResolvedConfig, UnresolvedConfig}; pub use services_config::ServicesConfig; diff --git a/crates/server-config/src/resolved_config.rs b/crates/server-config/src/resolved_config.rs index 5a87fa2ea5..2b19703972 100644 --- a/crates/server-config/src/resolved_config.rs +++ b/crates/server-config/src/resolved_config.rs @@ -18,6 +18,7 @@ use clap::{Args, Command, FromArgMatches}; use std::ffi::OsString; use std::net::SocketAddr; use std::ops::{Deref, DerefMut}; +use std::str::FromStr; use crate::args; use figment::{ @@ -36,6 +37,12 @@ pub struct UnresolvedConfig { dir_config: UnresolvedDirConfig, #[serde(flatten)] node_config: UnresolvedNodeConfig, + #[serde(default)] + pub log: Option, + + pub no_banner: Option, + + pub print_config: Option, } impl UnresolvedConfig { @@ -43,14 +50,45 @@ impl UnresolvedConfig { Ok(ResolvedConfig { dir_config: self.dir_config.resolve()?, node_config: self.node_config.resolve()?, + log: self.log, + no_banner: self.no_banner.unwrap_or(false), + print_config: self.print_config.unwrap_or(false), }) } } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct LogConfig { + pub format: LogFormat, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum LogFormat { + #[serde(rename = "logfmt")] + Logfmt, + #[serde(rename = "default")] + Default, +} + +impl FromStr for LogFormat { + type Err = String; + + fn from_str(s: &str) -> Result { + match s.trim().to_ascii_lowercase().as_str() { + "logfmt" => Ok(LogFormat::Logfmt), + "default" => Ok(LogFormat::Default), + _ => Err("Unsupported log format".to_string()), + } + } +} + #[derive(Clone, Debug)] pub struct ResolvedConfig { pub dir_config: ResolvedDirConfig, pub node_config: NodeConfig, + pub log: Option, + pub no_banner: bool, + pub print_config: bool, } impl Deref for ResolvedConfig { @@ -161,15 +199,12 @@ pub fn resolve_config( }; let config_builder = config_builder - .merge(Env::prefixed("FLUENCE_")) - .merge(cli_config.clone()); + .merge(Env::prefixed("FLUENCE_").split("_")) + .merge(cli_config); - let config: UnresolvedConfig = config_builder.extract()?; - let config = config.resolve()?; + let unresolved_config: UnresolvedConfig = config_builder.extract()?; - if let Some(true) = cli_config.print_config { - log::info!("Loaded config: {:#?}", config); - } + let config = unresolved_config.resolve()?; Ok(config) } diff --git a/crates/server-config/src/services_config.rs b/crates/server-config/src/services_config.rs index 02234f9399..319597c808 100644 --- a/crates/server-config/src/services_config.rs +++ b/crates/server-config/src/services_config.rs @@ -71,8 +71,8 @@ impl ServicesConfig { .map(|path_str| { let path = Path::new(&path_str); match path.try_exists() { - Err(err) => log::warn!("cannot check binary `{path_str}`: {err}"), - Ok(false) => log::warn!("binary `{path_str}` does not exist"), + Err(err) => println!("cannot check binary `{path_str}`: {err}"), + Ok(false) => println!("binary `{path_str}` does not exist"), _ => {} }; path.to_path_buf() diff --git a/particle-node/src/connectivity.rs b/particle-node/src/connectivity.rs index f9128adc92..5bfbb140f1 100644 --- a/particle-node/src/connectivity.rs +++ b/particle-node/src/connectivity.rs @@ -85,22 +85,22 @@ impl Connectivity { if let Some(m) = metrics { m.count_resolution(Resolution::ConnectionFailed) } - log::warn!( - "{} Couldn't connect to {} for particle {}", + tracing::warn!( + particle_id = particle_id, + "{} Couldn't connect to {}", self.peer_id, - target, - particle_id + target ); } Ok(None) => { if let Some(m) = metrics { m.count_resolution(Resolution::KademliaNotFound) } - log::warn!( - "{} Couldn't discover {} for particle {}", + tracing::warn!( + particle_id = particle_id, + "{} Couldn't discover {}", self.peer_id, - target, - particle_id + target ); } Err(err) => { @@ -108,11 +108,11 @@ impl Connectivity { m.count_resolution(Resolution::KademliaError) } let id = particle_id; - log::warn!( - "{} Failed to discover {} for particle {}: {}", + tracing::warn!( + particle_id = id, + "{} Failed to discover {}: {}", self.peer_id, target, - id, err ); } @@ -123,7 +123,7 @@ impl Connectivity { } pub async fn send(&self, contact: Contact, particle: Particle) -> bool { - log::debug!("Sending particle {} to {}", particle.id, contact); + tracing::debug!(particle_id = particle.id, "Sending particle to {}", contact); let metrics = self.metrics.as_ref(); let id = particle.id.clone(); let sent = self.connection_pool.send(contact.clone(), particle).await; @@ -132,15 +132,15 @@ impl Connectivity { if let Some(m) = metrics { m.send_particle_ok(&id) } - log::info!("Sent particle {} to {}", id, contact); + tracing::info!(particle_id = id, "Sent particle to {}", contact); } err => { if let Some(m) = metrics { m.send_particle_failed(&id); } - log::warn!( - "Failed to send particle {} to {}, reason: {:?}", - id, + tracing::warn!( + particle_id = id, + "Failed to send particle to {}, reason: {:?}", contact, err ) diff --git a/particle-node/src/dispatcher.rs b/particle-node/src/dispatcher.rs index e2ef14120c..276bd13771 100644 --- a/particle-node/src/dispatcher.rs +++ b/particle-node/src/dispatcher.rs @@ -97,7 +97,7 @@ impl Dispatcher { if let Some(m) = metrics { m.particle_expired(&particle.id); } - log::info!("Particle {} expired", particle.id); + tracing::info!(particle_id = particle.id, "Particle is expired"); return async {}.boxed(); } diff --git a/particle-node/src/effectors.rs b/particle-node/src/effectors.rs index 7101c5bf40..6f425540b1 100644 --- a/particle-node/src/effectors.rs +++ b/particle-node/src/effectors.rs @@ -38,7 +38,7 @@ impl Effectors { particle_failures: mpsc::UnboundedSender, ) { if effects.particle.is_expired() { - log::info!("Particle {} is expired", effects.particle.id); + tracing::info!(particle_id = effects.particle.id, "Particle is expired"); return; } diff --git a/particle-node/src/layers.rs b/particle-node/src/layers.rs index 496df653de..f596437443 100644 --- a/particle-node/src/layers.rs +++ b/particle-node/src/layers.rs @@ -2,6 +2,7 @@ use console_subscriber::ConsoleLayer; use opentelemetry::sdk::Resource; use opentelemetry::KeyValue; use opentelemetry_otlp::WithExportConfig; +use server_config::{LogConfig, LogFormat}; use tracing::level_filters::LevelFilter; use tracing::Subscriber; use tracing_subscriber::registry::LookupSpan; @@ -10,7 +11,7 @@ use tracing_subscriber::Layer; const TOKIO_CONSOLE_VAR: &str = "FLUENCE_TOKIO_CONSOLE_ENABLED"; const TRACING_TRACER_VAR: &str = "FLUENCE_TRACING_TRACER"; -pub fn log_layer() -> impl Layer +pub fn log_layer(log_config: Option) -> impl Layer where S: Subscriber + for<'span> LookupSpan<'span>, { @@ -32,7 +33,24 @@ where .add_directive("tracing=error".parse().unwrap()) .add_directive("avm_server::runner=error".parse().unwrap()); - tracing_logfmt::layer().with_filter(env_filter) + let log_format = log_config.map(|c| c.format).unwrap_or(LogFormat::Default); + + let layer = match log_format { + LogFormat::Logfmt => tracing_logfmt::builder() + .with_target(false) + .with_span_path(false) + .with_span_name(false) + .layer() + .with_filter(env_filter) + .boxed(), + LogFormat::Default => tracing_subscriber::fmt::layer() + .with_thread_ids(true) + .with_thread_names(true) + .with_filter(env_filter) + .boxed(), + }; + + layer } pub fn tokio_console_layer() -> Option> @@ -55,7 +73,6 @@ where .as_str() { "otlp" => { - log::debug!("Setup the OTLP tracer"); let resource = Resource::new(vec![KeyValue::new("service.name", "rust-peer")]); let tracer = opentelemetry_otlp::new_pipeline() @@ -67,10 +84,7 @@ where let tracing_layer = tracing_opentelemetry::layer::().with_tracer(tracer); Some(tracing_layer) } - _ => { - log::debug!("No tracer selected"); - None - } + _ => None, }; Ok(tracing_layer) } diff --git a/particle-node/src/main.rs b/particle-node/src/main.rs index 44d6fddf6b..c73107dabe 100644 --- a/particle-node/src/main.rs +++ b/particle-node/src/main.rs @@ -59,14 +59,19 @@ async fn main() -> eyre::Result<()> { #[cfg(feature = "dhat-heap")] let _profiler = dhat::Profiler::new_heap(); - tracing_subscriber::registry() - .with(log_layer()) - .with(tokio_console_layer()) - .with(tracing_layer()?) - .init(); + let version = format!("{}; AIR version {}", VERSION, air_interpreter_wasm::VERSION); + let authors = format!("by {AUTHORS}"); + let config_data = ConfigData { + binary_name: PKG_NAME.to_string(), + version, + authors, + description: DESCRIPTION.to_string(), + }; + let config = load_config(Some(config_data))?; - log::info!( - r#" + if !config.no_banner { + println!( + r#" +-------------------------------------------------+ | Hello from the Fluence Team. If you encounter | | any troubles with node operation, please update | @@ -77,16 +82,18 @@ async fn main() -> eyre::Result<()> { | github.com/fluencelabs/fluence/discussions | +-------------------------------------------------+ "# - ); - let version = format!("{}; AIR version {}", VERSION, air_interpreter_wasm::VERSION); - let authors = format!("by {AUTHORS}"); - let config_data = ConfigData { - binary_name: PKG_NAME.to_string(), - version, - authors, - description: DESCRIPTION.to_string(), - }; - let config = load_config(Some(config_data))?; + ); + } + + tracing_subscriber::registry() + .with(log_layer(config.log.clone())) + .with(tokio_console_layer()) + .with(tracing_layer()?) + .init(); + + if config.print_config { + log::info!("Loaded config: {:#?}", config); + } let interpreter_path = to_abs_path(config.dir_config.air_interpreter_path.clone()); write_default_air_interpreter(&interpreter_path)?; diff --git a/script-storage/Cargo.toml b/script-storage/Cargo.toml index 67815bbacc..1851e4c643 100644 --- a/script-storage/Cargo.toml +++ b/script-storage/Cargo.toml @@ -19,3 +19,4 @@ thiserror = { workspace = true } uuid = "1.3.1" chrono = "0.4.24" log = { workspace = true } +tracing = { workspace = true } diff --git a/script-storage/src/script_storage.rs b/script-storage/src/script_storage.rs index 5dee459eb0..cb0d5f0236 100644 --- a/script-storage/src/script_storage.rs +++ b/script-storage/src/script_storage.rs @@ -313,9 +313,9 @@ async fn remove_failed_scripts( }) .await; } else if particle_id.starts_with("auto") { - log::warn!( - "Reported auto particle {} as failed, but no scheduled script found", - particle_id + tracing::warn!( + particle_id = particle_id, + "Reported auto particle as failed, but no scheduled script found" ); } } diff --git a/sorcerer/Cargo.toml b/sorcerer/Cargo.toml index ff0fb678b3..a0057b83b1 100644 --- a/sorcerer/Cargo.toml +++ b/sorcerer/Cargo.toml @@ -30,6 +30,7 @@ fluence-keypair = { workspace = true } serde_json = { workspace = true } parking_lot = { workspace = true } log = { workspace = true } +tracing = { workspace = true } futures = { workspace = true } eyre = { workspace = true} fstrings = { workspace = true} diff --git a/sorcerer/src/spells.rs b/sorcerer/src/spells.rs index 4c6862ede1..8a6723318d 100644 --- a/sorcerer/src/spells.rs +++ b/sorcerer/src/spells.rs @@ -155,10 +155,10 @@ pub(crate) async fn spell_install( ))); } } else { - log::trace!( - "empty config given for spell {}, particle id {}", - spell_id, - params.id + tracing::trace!( + particle_id = params.id, + "empty config given for spell {}", + spell_id ); }