Skip to content

Commit 7e27939

Browse files
committed
refactor: remove log facade level
This is now considered unnecessary because the concrete implementation of the facade has control over the maximum log level that can be configured.
1 parent acf1d84 commit 7e27939

File tree

6 files changed

+18
-36
lines changed

6 files changed

+18
-36
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ interface Builder {
7474
void set_liquidity_source_lsps2(PublicKey node_id, SocketAddress address, string? token);
7575
void set_storage_dir_path(string storage_dir_path);
7676
void set_filesystem_logger(string? log_file_path, LogLevel? max_log_level);
77-
void set_log_facade_logger(LogLevel? max_log_level);
77+
void set_log_facade_logger();
7878
void set_custom_logger(LogWriter log_writer);
7979
void set_network(Network network);
8080
[Throws=BuildError]

src/builder.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct LiquiditySourceConfig {
113113
#[derive(Clone)]
114114
enum LogWriterConfig {
115115
File { log_file_path: Option<String>, max_log_level: Option<LogLevel> },
116-
Log { max_log_level: Option<LogLevel> },
116+
Log,
117117
Custom(Arc<dyn LogWriter>),
118118
}
119119

@@ -125,9 +125,7 @@ impl std::fmt::Debug for LogWriterConfig {
125125
.field("max_log_level", max_log_level)
126126
.field("log_file_path", log_file_path)
127127
.finish(),
128-
LogWriterConfig::Log { max_log_level } => {
129-
f.debug_tuple("Log").field(max_log_level).finish()
130-
},
128+
LogWriterConfig::Log => write!(f, "LogWriterConfig::Log"),
131129
LogWriterConfig::Custom(_) => {
132130
f.debug_tuple("Custom").field(&"<config internal to custom log writer>").finish()
133131
},
@@ -385,11 +383,8 @@ impl NodeBuilder {
385383
}
386384

387385
/// Configures the [`Node`] instance to write logs to the [`log`](https://crates.io/crates/log) facade.
388-
///
389-
/// If set, the `max_log_level` sets the maximum log level. Otherwise, the latter defaults to
390-
/// [`DEFAULT_LOG_LEVEL`].
391-
pub fn set_log_facade_logger(&mut self, max_log_level: Option<LogLevel>) -> &mut Self {
392-
self.log_writer_config = Some(LogWriterConfig::Log { max_log_level });
386+
pub fn set_log_facade_logger(&mut self) -> &mut Self {
387+
self.log_writer_config = Some(LogWriterConfig::Log);
393388
self
394389
}
395390

@@ -750,11 +745,8 @@ impl ArcedNodeBuilder {
750745
}
751746

752747
/// Configures the [`Node`] instance to write logs to the [`log`](https://crates.io/crates/log) facade.
753-
///
754-
/// If set, the `max_log_level` sets the maximum log level. Otherwise, the latter defaults to
755-
/// [`DEFAULT_LOG_LEVEL`].
756-
pub fn set_log_facade_logger(&self, log_level: Option<LogLevel>) {
757-
self.inner.write().unwrap().set_log_facade_logger(log_level);
748+
pub fn set_log_facade_logger(&self) {
749+
self.inner.write().unwrap().set_log_facade_logger();
758750
}
759751

760752
/// Configures the [`Node`] instance to write logs to the provided custom [`LogWriter`].
@@ -1421,10 +1413,7 @@ fn setup_logger(
14211413
Logger::new_fs_writer(log_file_path, max_log_level)
14221414
.map_err(|_| BuildError::LoggerSetupFailed)?
14231415
},
1424-
Some(LogWriterConfig::Log { max_log_level }) => {
1425-
let max_log_level = max_log_level.unwrap_or_else(|| DEFAULT_LOG_LEVEL);
1426-
Logger::new_log_facade(max_log_level)
1427-
},
1416+
Some(LogWriterConfig::Log) => Logger::new_log_facade(),
14281417

14291418
Some(LogWriterConfig::Custom(custom_log_writer)) => {
14301419
Logger::new_custom_writer(Arc::clone(&custom_log_writer))

src/logger.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub(crate) enum Writer {
108108
/// Writes logs to the file system.
109109
FileWriter { file_path: String, max_log_level: LogLevel },
110110
/// Forwards logs to the `log` facade.
111-
LogFacadeWriter { max_log_level: LogLevel },
111+
LogFacadeWriter,
112112
/// Forwards logs to a custom writer.
113113
CustomWriter(Arc<dyn LogWriter>),
114114
}
@@ -138,10 +138,7 @@ impl LogWriter for Writer {
138138
.write_all(log.as_bytes())
139139
.expect("Failed to write to log file")
140140
},
141-
Writer::LogFacadeWriter { max_log_level } => {
142-
if record.level < *max_log_level {
143-
return;
144-
}
141+
Writer::LogFacadeWriter => {
145142
macro_rules! log_with_level {
146143
($log_level:expr, $target: expr, $($args:tt)*) => {
147144
match $log_level {
@@ -186,8 +183,8 @@ impl Logger {
186183
Ok(Self { writer: Writer::FileWriter { file_path, max_log_level } })
187184
}
188185

189-
pub fn new_log_facade(max_log_level: LogLevel) -> Self {
190-
Self { writer: Writer::LogFacadeWriter { max_log_level } }
186+
pub fn new_log_facade() -> Self {
187+
Self { writer: Writer::LogFacadeWriter }
191188
}
192189

193190
pub fn new_custom_writer(log_writer: Arc<dyn LogWriter>) -> Self {
@@ -204,10 +201,7 @@ impl LdkLogger for Logger {
204201
}
205202
self.writer.log(record.into());
206203
},
207-
Writer::LogFacadeWriter { max_log_level } => {
208-
if record.level < *max_log_level {
209-
return;
210-
}
204+
Writer::LogFacadeWriter => {
211205
self.writer.log(record.into());
212206
},
213207
Writer::CustomWriter(_arc) => {

tests/common/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::{Arc, Mutex};
1010
#[derive(Clone)]
1111
pub(crate) enum TestLogWriter {
1212
FileWriter,
13-
LogFacade(LogLevel),
13+
LogFacade,
1414
Custom(Arc<dyn LogWriter>),
1515
}
1616

tests/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ pub(crate) fn setup_node(
328328
TestLogWriter::FileWriter => {
329329
builder.set_filesystem_logger(None, None);
330330
},
331-
TestLogWriter::LogFacade(max_log_level) => {
332-
builder.set_log_facade_logger(Some(*max_log_level));
331+
TestLogWriter::LogFacade => {
332+
builder.set_log_facade_logger();
333333
},
334334
TestLogWriter::Custom(custom_log_writer) => {
335335
builder.set_custom_logger(Arc::clone(custom_log_writer));

tests/integration_tests_rust.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ mod common;
1010
use common::{
1111
do_channel_full_cycle, expect_channel_pending_event, expect_channel_ready_event, expect_event,
1212
expect_payment_received_event, expect_payment_successful_event, generate_blocks_and_wait,
13-
logging::{init_custom_logger, init_log_logger, validate_log_entry, TestLogWriter},
13+
logging::{init_log_logger, validate_log_entry, TestLogWriter},
1414
open_channel, premine_and_distribute_funds, random_config, setup_bitcoind_and_electrsd,
1515
setup_builder, setup_node, setup_two_nodes, wait_for_tx, TestChainSource, TestSyncStore,
1616
};
1717

1818
use ldk_node::config::EsploraSyncConfig;
1919
use ldk_node::liquidity::LSPS2ServiceConfig;
2020

21-
use ldk_node::logger::LogLevel;
2221
use ldk_node::payment::{
2322
ConfirmationStatus, PaymentDirection, PaymentKind, PaymentStatus, QrPaymentResult,
2423
SendingParameters,
@@ -1156,7 +1155,7 @@ fn facade_logging() {
11561155

11571156
let logger = init_log_logger(LevelFilter::Trace);
11581157
let mut config = random_config(false);
1159-
config.log_writer = TestLogWriter::LogFacade(LogLevel::Gossip);
1158+
config.log_writer = TestLogWriter::LogFacade;
11601159

11611160
println!("== Facade logging starts ==");
11621161
let _node = setup_node(&chain_source, config, None);

0 commit comments

Comments
 (0)