Allow log threshold configuration.
authorArik Sosman <git@arik.io>
Fri, 4 Aug 2023 21:30:02 +0000 (14:30 -0700)
committerArik Sosman <git@arik.io>
Fri, 4 Aug 2023 21:30:02 +0000 (14:30 -0700)
src/config.rs
src/types.rs

index b0e3a7ce7722dafb236001df3e6bb46a1f6a60f7..804b0f8ff8a66262b7273702239b3ac645d24fae 100644 (file)
@@ -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())
 }
index 6fafbd3e340fb3507933889d6f47aef63f157ec2..0b03081f35814eda15182f110bcf96cbf9cc6993 100644 (file)
@@ -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);
        }
 }