Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ panic = 'abort' # Abort on panic

[features]
default = []
log_relay = ["log"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use any features in LDK Node so far (mostly to keep ~feature-parity of the Rust vs bindings API, for which everything needs to be configurable via the Builder), so please drop this and just take a non-optional dependency on log for now.


[dependencies]
lightning = { version = "0.0.125", features = ["std"] }
Expand Down Expand Up @@ -75,7 +76,7 @@ libc = "0.2"
uniffi = { version = "0.27.3", features = ["build"], optional = true }
serde = { version = "1.0.210", default-features = false, features = ["std", "derive"] }
serde_json = { version = "1.0.128", default-features = false, features = ["std"] }
log = { version = "0.4.22" }
log = { version = "0.4.22", optional = true}
vss-client = "0.3"
prost = { version = "0.11.6", default-features = false}

Expand Down
9 changes: 9 additions & 0 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) use lightning::{log_bytes, log_debug, log_error, log_info, log_trace}
use lightning::util::logger::{Level, Record};

use chrono::Utc;
#[cfg(feature = "log_relay")]
use log::{debug, error, info, trace, warn};

use std::fmt::Debug;
Expand All @@ -34,6 +35,7 @@ pub enum Writer {
/// Writes logs to filesystem.
FileWriter { log_file: Mutex<fs::File> },
/// Relays logs to [`log`] logger.
#[cfg(feature = "log_relay")]
LogRelayWriter,
/// Forwards logs to a custom logger.
CustomWriter { inner: Arc<dyn LogWriter + Send + Sync> },
Expand Down Expand Up @@ -68,11 +70,17 @@ impl Writer {
},
// Initial logic for Writer that forwards to any logger that
// implements the `log` facade.
#[cfg(feature = "log_relay")]
WriterType::LogRelay(_log_relay_writer_config) => Ok(Writer::LogRelayWriter),
// Initial logic for Writer that forwards to any custom logger.
WriterType::Custom(custom_writer_config) => {
Ok(Writer::CustomWriter { inner: custom_writer_config.inner.clone() })
},
#[cfg(not(feature = "log_relay"))]
_ => {
eprintln!("ERROR: log_relay feature is not enabled");
Err(())
},
}
}
}
Expand All @@ -85,6 +93,7 @@ impl LogWriter for Writer {
.expect("log file lock poisoned")
.write_all(message.as_bytes())
.expect("Failed to write to log file"),
#[cfg(feature = "log_relay")]
Writer::LogRelayWriter => match level {
Level::Gossip => {
// trace!(..) used for gossip logs here.
Expand Down
Loading