Skip to content

Commit 4e59771

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 37beb60 commit 4e59771

File tree

6 files changed

+17
-35
lines changed

6 files changed

+17
-35
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ interface Builder {
6262
void set_liquidity_source_lsps2(PublicKey node_id, SocketAddress address, string? token);
6363
void set_storage_dir_path(string storage_dir_path);
6464
void set_filesystem_logger(string? log_file_path, LogLevel? max_log_level);
65-
void set_log_facade_logger(LogLevel? max_log_level);
65+
void set_log_facade_logger();
6666
void set_custom_logger(LogWriter log_writer);
6767
void set_network(Network network);
6868
[Throws=BuildError]

src/builder.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Default for LiquiditySourceConfig {
111111
#[derive(Clone)]
112112
enum LogWriterConfig {
113113
File { log_file_path: Option<String>, max_log_level: Option<LogLevel> },
114-
Log { max_log_level: Option<LogLevel> },
114+
Log,
115115
Custom(Arc<dyn LogWriter>),
116116
}
117117

@@ -123,9 +123,7 @@ impl std::fmt::Debug for LogWriterConfig {
123123
.field("max_log_level", max_log_level)
124124
.field("log_file_path", log_file_path)
125125
.finish(),
126-
LogWriterConfig::Log { max_log_level } => {
127-
f.debug_tuple("Log").field(max_log_level).finish()
128-
},
126+
LogWriterConfig::Log => write!(f, "LogWriterConfig::Log"),
129127
LogWriterConfig::Custom(_) => {
130128
f.debug_tuple("Custom").field(&"<config internal to custom log writer>").finish()
131129
},
@@ -366,11 +364,8 @@ impl NodeBuilder {
366364
}
367365

368366
/// Configures the [`Node`] instance to write logs to the [`log`](https://crates.io/crates/log) facade.
369-
///
370-
/// If set, the `max_log_level` sets the maximum log level. Otherwise, the latter defaults to
371-
/// [`DEFAULT_LOG_LEVEL`].
372-
pub fn set_log_facade_logger(&mut self, max_log_level: Option<LogLevel>) -> &mut Self {
373-
self.log_writer_config = Some(LogWriterConfig::Log { max_log_level });
367+
pub fn set_log_facade_logger(&mut self) -> &mut Self {
368+
self.log_writer_config = Some(LogWriterConfig::Log);
374369
self
375370
}
376371

@@ -712,11 +707,8 @@ impl ArcedNodeBuilder {
712707
}
713708

714709
/// Configures the [`Node`] instance to write logs to the [`log`](https://crates.io/crates/log) facade.
715-
///
716-
/// If set, the `max_log_level` sets the maximum log level. Otherwise, the latter defaults to
717-
/// [`DEFAULT_LOG_LEVEL`].
718-
pub fn set_log_facade_logger(&self, log_level: Option<LogLevel>) {
719-
self.inner.write().unwrap().set_log_facade_logger(log_level);
710+
pub fn set_log_facade_logger(&self) {
711+
self.inner.write().unwrap().set_log_facade_logger();
720712
}
721713

722714
/// Configures the [`Node`] instance to write logs to the provided custom [`LogWriter`].
@@ -1355,10 +1347,7 @@ fn setup_logger(
13551347
Logger::new_fs_writer(log_file_path, max_log_level)
13561348
.map_err(|_| BuildError::LoggerSetupFailed)?
13571349
},
1358-
Some(LogWriterConfig::Log { max_log_level }) => {
1359-
let max_log_level = max_log_level.unwrap_or_else(|| DEFAULT_LOG_LEVEL);
1360-
Logger::new_log_facade(max_log_level)
1361-
},
1350+
Some(LogWriterConfig::Log) => Logger::new_log_facade(),
13621351

13631352
Some(LogWriterConfig::Custom(custom_log_writer)) => {
13641353
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use common::{
1616
};
1717

1818
use ldk_node::config::EsploraSyncConfig;
19-
use ldk_node::logger::LogLevel;
2019
use ldk_node::payment::{
2120
ConfirmationStatus, PaymentDirection, PaymentKind, PaymentStatus, QrPaymentResult,
2221
SendingParameters,
@@ -1049,7 +1048,7 @@ fn facade_logging() {
10491048

10501049
let logger = init_log_logger(LevelFilter::Trace);
10511050
let mut config = random_config(false);
1052-
config.log_writer = TestLogWriter::LogFacade(LogLevel::Gossip);
1051+
config.log_writer = TestLogWriter::LogFacade;
10531052

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

0 commit comments

Comments
 (0)