Skip to content

Commit

Permalink
Allow log threshold configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Aug 4, 2023
1 parent 3f500ef commit 5eb833b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
6 changes: 5 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

0 comments on commit 5eb833b

Please sign in to comment.