node: Improved message logging

This commit is contained in:
cloudhead 2024-04-23 10:41:43 +02:00
parent d77b5d5abe
commit cdebbe5bb7
No known key found for this signature in database
2 changed files with 17 additions and 8 deletions

View File

@ -461,17 +461,17 @@ impl Message {
}; };
let msg = match self { let msg = match self {
Self::Announcement(Announcement { node, message, .. }) => match message { Self::Announcement(Announcement { node, message, .. }) => match message {
AnnouncementMessage::Node(NodeAnnouncement { addresses, .. }) => format!( AnnouncementMessage::Node(NodeAnnouncement { addresses, timestamp, .. }) => format!(
"{verb} node announcement of {node} with {} address(es) {prep} {remote}", "{verb} node announcement of {node} with {} address(es) {prep} {remote} (t={timestamp})",
addresses.len() addresses.len()
), ),
AnnouncementMessage::Refs(RefsAnnouncement { rid, refs, .. }) => format!( AnnouncementMessage::Refs(RefsAnnouncement { rid, refs, timestamp }) => format!(
"{verb} refs announcement of {node} for {rid} with {} remote(s) {prep} {remote}", "{verb} refs announcement of {node} for {rid} with {} remote(s) {prep} {remote} (t={timestamp})",
refs.len() refs.len()
), ),
AnnouncementMessage::Inventory(InventoryAnnouncement { inventory, .. }) => { AnnouncementMessage::Inventory(InventoryAnnouncement { inventory, timestamp }) => {
format!( format!(
"{verb} inventory announcement of {node} with {} item(s) {prep} {remote}", "{verb} inventory announcement of {node} with {} item(s) {prep} {remote} (t={timestamp})",
inventory.len() inventory.len()
) )
} }

View File

@ -12,13 +12,22 @@ impl Log for Logger {
fn log(&self, record: &Record) { fn log(&self, record: &Record) {
use colored::Colorize; use colored::Colorize;
let time = LocalTime::now().as_secs();
match record.target() { match record.target() {
"test" => { "test" => {
println!("{} {}", "test:".cyan(), record.args().to_string().cyan()) println!(
"{time} {} {}",
"test:".cyan(),
record.args().to_string().cyan()
)
} }
"sim" => { "sim" => {
println!("{} {}", "sim:".bold(), record.args().to_string().bold()) println!(
"{time} {} {}",
"sim:".bold(),
record.args().to_string().bold()
)
} }
target => { target => {
if self.enabled(record.metadata()) { if self.enabled(record.metadata()) {