Skip to content

Commit

Permalink
feat(nodeman): add LogFormat as a startup arg for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef authored and jacderida committed May 17, 2024
1 parent b656a59 commit 76fad0a
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 15 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.

1 change: 1 addition & 0 deletions node-launchpad/src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ fn add_and_start_nodes(
None,
None,
None,
None,
peers,
None,
None,
Expand Down
15 changes: 5 additions & 10 deletions sn_logging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ opentelemetry = { version = "0.20", features = ["rt-tokio"], optional = true }
opentelemetry-otlp = { version = "0.13", optional = true }
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
rand = { version = "~0.8.5", features = ["small_rng"], optional = true }
serde = { version = "1.0.133", features = [ "derive", "rc" ], optional = true }
serde_json = {version = "1.0", optional = true }
serde = { version = "1.0.133", features = ["derive", "rc"] }
serde_json = { version = "1.0" }
sysinfo = { version = "0.30.8", default-features = false, optional = true }
thiserror = "1.0.23"
tokio = { version = "1.32.0", optional = true }
tracing = { version = "~0.1.26" }
tracing-appender = "~0.2.0"
tracing-core = "0.1.30"
tracing-opentelemetry = { version = "0.21", optional = true }
tracing-subscriber = { version = "0.3.16", features=["json"] }
tracing-subscriber = { version = "0.3.16", features = ["json"] }

[dev-dependencies]
color-eyre = "~0.6"
Expand All @@ -39,15 +39,10 @@ otlp = [
"opentelemetry-otlp",
"opentelemetry-semantic-conventions",
"tracing-opentelemetry",
"rand/small_rng"
"rand/small_rng",
]
test-utils = []
process-metrics = [
"serde",
"serde_json",
"sysinfo",
"tokio"
]
process-metrics = ["sysinfo", "tokio"]

[lints]
workspace = true
10 changes: 9 additions & 1 deletion sn_logging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod metrics;

use crate::error::Result;
use layers::TracingLayers;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use tracing::info;
use tracing_appender::non_blocking::WorkerGuard;
Expand Down Expand Up @@ -92,7 +93,7 @@ impl std::fmt::Display for LogOutputDest {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum LogFormat {
Default,
Json,
Expand All @@ -108,6 +109,13 @@ impl LogFormat {
)),
}
}

pub fn as_str(&self) -> &'static str {
match self {
LogFormat::Default => "default",
LogFormat::Json => "json",
}
}
}

pub struct LogBuilder {
Expand Down
1 change: 1 addition & 0 deletions sn_node_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ semver = "1.0.20"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
service-manager = "0.6.1"
sn_logging = { path = "../sn_logging", version = "0.2.26" }
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.2.12" }
sn_protocol = { path = "../sn_protocol", version = "0.16.5" }
sn_service_management = { path = "../sn_service_management", version = "0.2.7" }
Expand Down
8 changes: 7 additions & 1 deletion sn_node_manager/src/add_services/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use color_eyre::{eyre::eyre, Result};
use libp2p::Multiaddr;
use service_manager::{ServiceInstallCtx, ServiceLabel};
use sn_logging::LogFormat;
use std::{
ffi::OsString,
net::{Ipv4Addr, SocketAddr},
Expand Down Expand Up @@ -48,6 +49,7 @@ pub struct InstallNodeServiceCtxBuilder {
pub home_network: bool,
pub local: bool,
pub log_dir_path: PathBuf,
pub log_format: Option<LogFormat>,
pub name: String,
pub metrics_port: Option<u16>,
pub node_port: Option<u16>,
Expand Down Expand Up @@ -78,6 +80,10 @@ impl InstallNodeServiceCtxBuilder {
if self.local {
args.push(OsString::from("--local"));
}
if let Some(log_format) = self.log_format {
args.push(OsString::from("--log-format"));
args.push(OsString::from(log_format.as_str()));
}
if self.upnp {
args.push(OsString::from("--upnp"));
}
Expand All @@ -89,7 +95,6 @@ impl InstallNodeServiceCtxBuilder {
args.push(OsString::from("--metrics-server-port"));
args.push(OsString::from(metrics_port.to_string()));
}

if !self.bootstrap_peers.is_empty() {
let peers_str = self
.bootstrap_peers
Expand Down Expand Up @@ -121,6 +126,7 @@ pub struct AddNodeServiceOptions {
pub genesis: bool,
pub home_network: bool,
pub local: bool,
pub log_format: Option<LogFormat>,
pub metrics_port: Option<PortRange>,
pub node_port: Option<PortRange>,
pub rpc_address: Option<Ipv4Addr>,
Expand Down
2 changes: 2 additions & 0 deletions sn_node_manager/src/add_services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub async fn add_node(
home_network: options.home_network,
local: options.local,
log_dir_path: service_log_dir_path.clone(),
log_format: options.log_format,
metrics_port,
name: service_name.clone(),
node_port,
Expand Down Expand Up @@ -215,6 +216,7 @@ pub async fn add_node(
listen_addr: None,
local: options.local,
log_dir_path: service_log_dir_path.clone(),
log_format: options.log_format,
metrics_port,
node_port,
number: node_number,
Expand Down
Loading

0 comments on commit 76fad0a

Please sign in to comment.