Skip to content

Commit

Permalink
refactor: simplify Debug trait implementations for LogWriterConfig
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
enigbe committed Dec 17, 2024
1 parent 283fe85 commit 9f87227
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 13 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,25 @@ impl Default for LiquiditySourceConfig {
}
}

#[derive(Debug, Clone)]
#[derive(Clone)]
enum LogWriterConfig {
File(FilesystemLoggerConfig),
Log(LogLevel),
Custom(Arc<dyn LogWriter + Send + Sync>),
}

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(&"<config internal to custom log writer>").finish()
},
}
}
}

impl Default for LogWriterConfig {
fn default() -> Self {
Self::File(FilesystemLoggerConfig::default())
Expand Down
6 changes: 2 additions & 4 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +78,7 @@ impl<'a> From<Record<'a>> 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>);
}
Expand All @@ -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 },
Expand Down
5 changes: 0 additions & 5 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ pub(crate) enum TestLogWriter {
}

/// Simple in-memory mock `log` logger for tests.
#[derive(Debug)]
pub(crate) struct MockLogger {
logs: Arc<Mutex<Vec<String>>>,
}
Expand Down Expand Up @@ -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!(
Expand Down

0 comments on commit 9f87227

Please sign in to comment.