From: Arik Sosman Date: Fri, 4 Aug 2023 21:30:02 +0000 (-0700) Subject: Allow log threshold configuration. X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=5eb833bb7ca47f76d8853e44121cfc785fe1a1c3;p=rapid-gossip-sync-server Allow log threshold configuration. --- diff --git a/src/config.rs b/src/config.rs index b0e3a7c..804b0f8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,6 +35,19 @@ pub(crate) fn network() -> Network { } } +pub(crate) fn log_level() -> lightning::util::logger::Level { + let level = env::var("RAPID_GOSSIP_SYNC_SERVER_LOG_LEVEL").unwrap_or("info".to_string()).to_lowercase(); + match level.as_str() { + "gossip" => lightning::util::logger::Level::Gossip, + "trace" => lightning::util::logger::Level::Trace, + "debug" => lightning::util::logger::Level::Debug, + "info" => lightning::util::logger::Level::Info, + "warn" => lightning::util::logger::Level::Warn, + "error" => lightning::util::logger::Level::Error, + _ => panic!("Invalid log level"), + } +} + pub(crate) fn network_graph_cache_path() -> String { format!("{}/network_graph.bin", cache_path()) } diff --git a/src/types.rs b/src/types.rs index 6fafbd3..0b03081 100644 --- a/src/types.rs +++ b/src/types.rs @@ -4,6 +4,7 @@ use lightning::sign::KeysManager; use lightning::ln::msgs::{ChannelAnnouncement, ChannelUpdate}; use lightning::ln::peer_handler::{ErroringMessageHandler, IgnoringMessageHandler, PeerManager}; use lightning::util::logger::{Logger, Record}; +use crate::config; use crate::downloader::GossipRouter; use crate::verifier::ChainVerifier; @@ -28,7 +29,10 @@ impl RGSSLogger { impl Logger for RGSSLogger { fn log(&self, record: &Record) { - // TODO: allow log level threshold to be set + let threshold = config::log_level(); + if record.level < threshold { + return; + } println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args); } }