Skip to content

Commit

Permalink
chore: clean up and improve logging for random activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifeanyichukwu committed Apr 22, 2024
1 parent 19f7162 commit c14ef99
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ struct Payment {
dispatch_time: SystemTime,
}

impl Payment {
fn formatted_activity_name(&self) -> String {
if self.activity_name != "" {
format!("{} activity:", self.activity_name)
} else {
"".to_string()
}
}
}

impl Display for Payment {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let dispatch_time = self
Expand All @@ -367,8 +377,8 @@ impl Display for Payment {

write!(
f,
"{} activity: Payment {} dispatched at {:?} sending {} msat from {} -> {}",
self.activity_name,
"{} Payment {} dispatched at {:?} sending {} msat from {} -> {}",
self.formatted_activity_name(),
self.hash.map(|h| hex::encode(h.0)).unwrap_or_default(),
dispatch_time,
self.amount_msat,
Expand Down Expand Up @@ -1118,20 +1128,17 @@ impl PaymentResultLogger {
}

self.total_sent += details.amount_msat;
self.activity_name = details.activity_name.clone();
self.activity_name = details.formatted_activity_name();
}
}

// TODO: Add activity name and handle the initial processing log with few LOC
impl Display for PaymentResultLogger {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let total_payments = self.success_payment + self.failed_payment;

// if self.activity_name

write!(
f,
"{} activity: Processed {} payments sending {} msat total with {:.2}% success rate.",
"{} Processed {} payments sending {} msat total with {:.2}% success rate.",
self.activity_name,
total_payments,
self.total_sent,
Expand Down

0 comments on commit c14ef99

Please sign in to comment.