Skip to content

Commit

Permalink
Fix log-facade logging
Browse files Browse the repository at this point in the history
Previously, the log facade logger would always use a `logger` target but
then *also* add the correct module path and line as part of the normal
log messages. Here, we override the log target correctly.

Moreover, we previously would log all messages at the configured
*maximum* level, not the level in the log record.
  • Loading branch information
tnull committed Feb 1, 2025
1 parent ecec232 commit c8fb1fc
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,19 @@ impl LogWriter for Writer {
return;
}
macro_rules! log_with_level {
($log_level:expr, $($args:tt)*) => {
($log_level:expr, $target: expr, $($args:tt)*) => {
match $log_level {
LogLevel::Gossip | LogLevel::Trace => trace!($($args)*),
LogLevel::Debug => debug!($($args)*),
LogLevel::Info => info!($($args)*),
LogLevel::Warn => warn!($($args)*),
LogLevel::Error => error!($($args)*),
LogLevel::Gossip | LogLevel::Trace => trace!(target: $target, $($args)*),
LogLevel::Debug => debug!(target: $target, $($args)*),
LogLevel::Info => info!(target: $target, $($args)*),
LogLevel::Warn => warn!(target: $target, $($args)*),
LogLevel::Error => error!(target: $target, $($args)*),
}
};
}

log_with_level!(
max_log_level,
"{} {:<5} [{}:{}] {}",
Utc::now().format("%Y-%m-%d %H:%M:%S"),
record.level,
record.module_path,
record.line,
record.args
)
let target = format!("[{}:{}]", record.module_path, record.line);
log_with_level!(record.level, &target, " {}", record.args)
},
Writer::CustomWriter(custom_logger) => custom_logger.log(record),
}
Expand Down

0 comments on commit c8fb1fc

Please sign in to comment.