From: Matt Corallo Date: Mon, 19 Aug 2024 21:07:46 +0000 (+0000) Subject: Remove log level filtering in tests X-Git-Tag: v0.0.124~3^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=cdcab1ce1bb164f21222b7e038aa52c08025af30;p=rust-lightning Remove log level filtering in tests There's no reason why we should be filtering our logs during tests. It seems mostly like the `TestLogger` was written more as a sample logger than a test logger, but these days we have samples, so we should just drop the filtering and show everything. --- diff --git a/lightning-rapid-gossip-sync/src/processing.rs b/lightning-rapid-gossip-sync/src/processing.rs index a9757e04d..b87c1be39 100644 --- a/lightning-rapid-gossip-sync/src/processing.rs +++ b/lightning-rapid-gossip-sync/src/processing.rs @@ -476,7 +476,6 @@ mod tests { use lightning::ln::msgs::DecodeError; use lightning::routing::gossip::{NetworkGraph, NodeId}; - use lightning::util::logger::Level; use lightning::util::test_utils::TestLogger; use crate::processing::STALE_RGS_UPDATE_AGE_LIMIT_SECS; @@ -534,8 +533,7 @@ mod tests { #[test] fn node_data_update_succeeds_with_v2() { - let mut logger = TestLogger::new(); - logger.enable(Level::Gossip); + let logger = TestLogger::new(); let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); let example_input = vec![ @@ -597,8 +595,7 @@ mod tests { #[test] fn node_date_update_succeeds_without_channels() { - let mut logger = TestLogger::new(); - logger.enable(Level::Gossip); + let logger = TestLogger::new(); let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); let rapid_sync = RapidGossipSync::new(&network_graph, &logger); @@ -626,8 +623,7 @@ mod tests { #[test] fn update_ignores_v2_additional_data() { - let mut logger = TestLogger::new(); - logger.enable(Level::Gossip); + let logger = TestLogger::new(); let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); let rapid_sync = RapidGossipSync::new(&network_graph, &logger); diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index cba5dbb77..56e609ca4 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -294,8 +294,7 @@ mod tests { #[test] fn test_logging_macros() { - let mut logger = TestLogger::new(); - logger.enable(Level::Gossip); + let logger = TestLogger::new(); let logger : Arc = Arc::new(logger); let wrapper = WrapperLog::new(Arc::clone(&logger)); wrapper.call_macros(); diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 13d7b138f..7a0f75a57 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -43,7 +43,7 @@ use crate::routing::scoring::{ChannelUsage, ScoreUpdate, ScoreLookUp}; use crate::sync::RwLock; use crate::util::config::UserConfig; use crate::util::test_channel_signer::{TestChannelSigner, EnforcementState}; -use crate::util::logger::{Logger, Level, Record}; +use crate::util::logger::{Logger, Record}; use crate::util::ser::{Readable, ReadableArgs, Writer, Writeable}; use crate::util::persist::KVStore; @@ -1117,7 +1117,6 @@ impl events::MessageSendEventsProvider for TestRoutingMessageHandler { } pub struct TestLogger { - level: Level, pub(crate) id: String, pub lines: Mutex>, pub context: Mutex, Option), usize>>, @@ -1129,15 +1128,11 @@ impl TestLogger { } pub fn with_id(id: String) -> TestLogger { TestLogger { - level: Level::Trace, id, lines: Mutex::new(new_hash_map()), context: Mutex::new(new_hash_map()), } } - pub fn enable(&mut self, level: Level) { - self.level = level; - } pub fn assert_log(&self, module: &str, line: String, count: usize) { let log_entries = self.lines.lock().unwrap(); assert_eq!(log_entries.get(&(module, line)), Some(&count)); @@ -1181,10 +1176,8 @@ impl Logger for TestLogger { fn log(&self, record: Record) { *self.lines.lock().unwrap().entry((record.module_path, format!("{}", record.args))).or_insert(0) += 1; *self.context.lock().unwrap().entry((record.module_path, record.peer_id, record.channel_id)).or_insert(0) += 1; - if record.level >= self.level { - let pfx = format!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line); - println!("{:<55}{}", pfx, record.args); - } + let pfx = format!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line); + println!("{:<55}{}", pfx, record.args); } }