From 5eb833bb7ca47f76d8853e44121cfc785fe1a1c3 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Fri, 4 Aug 2023 14:30:02 -0700 Subject: [PATCH] Allow log threshold configuration. --- src/config.rs | 13 +++++++++++++ src/types.rs | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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); } } -- 2.30.2