Skip to content

Commit 9f87227

Browse files
committed
refactor: simplify Debug trait implementations for LogWriterConfig
- Add a custom Debug implementation for LogWriterConfig to work around NodeBuilder's Debug constraints. - Remove the Debug trait from LogWriter, as it is no longer needed due to the custom Debug impl on LogWriterConfig. - Remove the Debug implementation from Writer for consistency.
1 parent 283fe85 commit 9f87227

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/builder.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,25 @@ impl Default for LiquiditySourceConfig {
109109
}
110110
}
111111

112-
#[derive(Debug, Clone)]
112+
#[derive(Clone)]
113113
enum LogWriterConfig {
114114
File(FilesystemLoggerConfig),
115115
Log(LogLevel),
116116
Custom(Arc<dyn LogWriter + Send + Sync>),
117117
}
118118

119+
impl std::fmt::Debug for LogWriterConfig {
120+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
121+
match self {
122+
LogWriterConfig::File(config) => f.debug_tuple("File").field(config).finish(),
123+
LogWriterConfig::Log(level) => f.debug_tuple("Log").field(level).finish(),
124+
LogWriterConfig::Custom(_) => {
125+
f.debug_tuple("Custom").field(&"<config internal to custom log writer>").finish()
126+
},
127+
}
128+
}
129+
}
130+
119131
impl Default for LogWriterConfig {
120132
fn default() -> Self {
121133
Self::File(FilesystemLoggerConfig::default())

src/logger.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use log::{debug, error, info, trace, warn};
1717

1818
#[cfg(not(feature = "uniffi"))]
1919
use core::fmt;
20-
use std::fmt::Debug;
2120
use std::fs;
2221
use std::io::Write;
2322
use std::path::Path;
@@ -79,7 +78,7 @@ impl<'a> From<Record<'a>> for LogRecord<'a> {
7978
/// which may involve formatting, filtering, and forwarding them to specific
8079
/// outputs.
8180
#[cfg(not(feature = "uniffi"))]
82-
pub trait LogWriter: Send + Sync + Debug {
81+
pub trait LogWriter: Send + Sync {
8382
/// Log the record.
8483
fn log<'a>(&self, record: LogRecord<'a>);
8584
}
@@ -90,13 +89,12 @@ pub trait LogWriter: Send + Sync + Debug {
9089
/// It is similar to the non-`uniffi` version, but it omits the lifetime parameter
9190
/// for the `LogRecord`, as the Uniffi-exposed interface cannot handle lifetimes.
9291
#[cfg(feature = "uniffi")]
93-
pub trait LogWriter: Send + Sync + Debug {
92+
pub trait LogWriter: Send + Sync {
9493
/// Log the record.
9594
fn log(&self, record: LogRecord);
9695
}
9796

9897
/// Defines a writer for [`Logger`].
99-
#[derive(Debug)]
10098
pub(crate) enum Writer {
10199
/// Writes logs to the file system.
102100
FileWriter { file_path: String, level: LogLevel },

tests/common/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ pub(crate) enum TestLogWriter {
260260
}
261261

262262
/// Simple in-memory mock `log` logger for tests.
263-
#[derive(Debug)]
264263
pub(crate) struct MockLogger {
265264
logs: Arc<Mutex<Vec<String>>>,
266265
}
@@ -297,10 +296,6 @@ impl Log for MockLogger {
297296
fn flush(&self) {}
298297
}
299298

300-
/// [`MockLogger`] as custom logger - a destination for [`Writer::CustomWriter`]
301-
/// to write logs to.
302-
///
303-
/// [`Writer::CustomWriter`]: ldk_node::logger::Writer::CustomWriter
304299
impl LogWriter for MockLogger {
305300
fn log(&self, record: LogRecord) {
306301
let message = format!(

0 commit comments

Comments
 (0)