From 9f87227a04dd4936df70f69212b529d7b2a6913f Mon Sep 17 00:00:00 2001 From: Enigbe Date: Tue, 17 Dec 2024 05:19:13 +0100 Subject: [PATCH] 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. --- src/builder.rs | 14 +++++++++++++- src/logger.rs | 6 ++---- tests/common/mod.rs | 5 ----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 46c34a97a..64e9c1931 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -109,13 +109,25 @@ impl Default for LiquiditySourceConfig { } } -#[derive(Debug, Clone)] +#[derive(Clone)] enum LogWriterConfig { File(FilesystemLoggerConfig), Log(LogLevel), Custom(Arc), } +impl std::fmt::Debug for LogWriterConfig { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + LogWriterConfig::File(config) => f.debug_tuple("File").field(config).finish(), + LogWriterConfig::Log(level) => f.debug_tuple("Log").field(level).finish(), + LogWriterConfig::Custom(_) => { + f.debug_tuple("Custom").field(&"").finish() + }, + } + } +} + impl Default for LogWriterConfig { fn default() -> Self { Self::File(FilesystemLoggerConfig::default()) diff --git a/src/logger.rs b/src/logger.rs index 97c047b30..794e85976 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -17,7 +17,6 @@ use log::{debug, error, info, trace, warn}; #[cfg(not(feature = "uniffi"))] use core::fmt; -use std::fmt::Debug; use std::fs; use std::io::Write; use std::path::Path; @@ -79,7 +78,7 @@ impl<'a> From> for LogRecord<'a> { /// which may involve formatting, filtering, and forwarding them to specific /// outputs. #[cfg(not(feature = "uniffi"))] -pub trait LogWriter: Send + Sync + Debug { +pub trait LogWriter: Send + Sync { /// Log the record. fn log<'a>(&self, record: LogRecord<'a>); } @@ -90,13 +89,12 @@ pub trait LogWriter: Send + Sync + Debug { /// It is similar to the non-`uniffi` version, but it omits the lifetime parameter /// for the `LogRecord`, as the Uniffi-exposed interface cannot handle lifetimes. #[cfg(feature = "uniffi")] -pub trait LogWriter: Send + Sync + Debug { +pub trait LogWriter: Send + Sync { /// Log the record. fn log(&self, record: LogRecord); } /// Defines a writer for [`Logger`]. -#[derive(Debug)] pub(crate) enum Writer { /// Writes logs to the file system. FileWriter { file_path: String, level: LogLevel }, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 78dbe9923..8e3fbd117 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -260,7 +260,6 @@ pub(crate) enum TestLogWriter { } /// Simple in-memory mock `log` logger for tests. -#[derive(Debug)] pub(crate) struct MockLogger { logs: Arc>>, } @@ -297,10 +296,6 @@ impl Log for MockLogger { fn flush(&self) {} } -/// [`MockLogger`] as custom logger - a destination for [`Writer::CustomWriter`] -/// to write logs to. -/// -/// [`Writer::CustomWriter`]: ldk_node::logger::Writer::CustomWriter impl LogWriter for MockLogger { fn log(&self, record: LogRecord) { let message = format!(