use core::fmt;
use core::ops::Deref;
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
#[cfg(c_bindings)]
use crate::prelude::*; // Needed for String
}
}
+macro_rules! impl_record {
+ ($($args: lifetime)?, $($nonstruct_args: lifetime)?) => {
/// A Record, unit of logging output with Metadata to enable filtering
/// Module_path, file, line to inform on log's source
#[derive(Clone, Debug)]
-pub struct Record<'a> {
+pub struct Record<$($args)?> {
/// The verbosity level of the message.
pub level: Level,
/// The node id of the peer pertaining to the logged record.
pub file: &'static str,
/// The line containing the message.
pub line: u32,
-
- #[cfg(c_bindings)]
- /// We don't actually use the lifetime parameter in C bindings (as there is no good way to
- /// communicate a lifetime to a C, or worse, Java user).
- _phantom: core::marker::PhantomData<&'a ()>,
}
-impl<'a> Record<'a> {
+impl<$($args)?> Record<$($args)?> {
/// Returns a new Record.
///
/// This is not exported to bindings users as fmt can't be used in C
#[inline]
- pub fn new(
+ pub fn new<$($nonstruct_args)?>(
level: Level, peer_id: Option<PublicKey>, channel_id: Option<ChannelId>,
args: fmt::Arguments<'a>, module_path: &'static str, file: &'static str, line: u32
- ) -> Record<'a> {
+ ) -> Record<$($args)?> {
Record {
level,
peer_id,
module_path,
file,
line,
- #[cfg(c_bindings)]
- _phantom: core::marker::PhantomData,
}
}
}
+} }
+#[cfg(not(c_bindings))]
+impl_record!('a, );
+#[cfg(c_bindings)]
+impl_record!(, 'a);
/// A trait encapsulating the operations required of a logger.
pub trait Logger {
}
/// Adds relevant context to a [`Record`] before passing it to the wrapped [`Logger`].
+///
+/// This is not exported to bindings users as lifetimes are problematic and there's little reason
+/// for this to be used downstream anyway.
pub struct WithContext<'a, L: Deref> where L::Target: Logger {
/// The logger to delegate to after adding context to the record.
logger: &'a L,
#[cfg(test)]
mod tests {
use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
- use crate::ln::ChannelId;
+ use crate::ln::types::ChannelId;
use crate::util::logger::{Logger, Level, WithContext};
use crate::util::test_utils::TestLogger;
use crate::sync::Arc;
}
struct WrapperLog {
- logger: Arc<Logger>
+ logger: Arc<dyn Logger>
}
impl WrapperLog {
- fn new(logger: Arc<Logger>) -> WrapperLog {
+ fn new(logger: Arc<dyn Logger>) -> WrapperLog {
WrapperLog {
logger,
}
fn test_logging_macros() {
let mut logger = TestLogger::new();
logger.enable(Level::Gossip);
- let logger : Arc<Logger> = Arc::new(logger);
+ let logger : Arc<dyn Logger> = Arc::new(logger);
let wrapper = WrapperLog::new(Arc::clone(&logger));
wrapper.call_macros();
}