Skip to content

Commit 6a9a4db

Browse files
authored
Adds microsecond logging and also reformats duration to include milliseconds (#156)
* Adds microsecond logging and also reformats duration to include milliseconds * fmt * attempt to fix cd * revert
1 parent 976b406 commit 6a9a4db

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

src/main.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ use crate::stats::{Collector, Reporter, REPORTER};
7474

7575
#[tokio::main(worker_threads = 4)]
7676
async fn main() {
77-
env_logger::init();
77+
env_logger::builder().format_timestamp_micros().init();
78+
7879
info!("Welcome to PgCat! Meow. (Version {})", VERSION);
7980

8081
if !query_router::QueryRouter::setup() {
@@ -307,34 +308,18 @@ async fn main() {
307308
///
308309
/// * `duration` - A duration of time
309310
fn format_duration(duration: &chrono::Duration) -> String {
310-
let seconds = {
311-
let seconds = duration.num_seconds() % 60;
312-
if seconds < 10 {
313-
format!("0{}", seconds)
314-
} else {
315-
format!("{}", seconds)
316-
}
317-
};
311+
let milliseconds = format!("{:0>3}", duration.num_milliseconds() % 1000);
318312

319-
let minutes = {
320-
let minutes = duration.num_minutes() % 60;
321-
if minutes < 10 {
322-
format!("0{}", minutes)
323-
} else {
324-
format!("{}", minutes)
325-
}
326-
};
313+
let seconds = format!("{:0>2}", duration.num_seconds() % 60);
327314

328-
let hours = {
329-
let hours = duration.num_hours() % 24;
330-
if hours < 10 {
331-
format!("0{}", hours)
332-
} else {
333-
format!("{}", hours)
334-
}
335-
};
315+
let minutes = format!("{:0>2}", duration.num_minutes() % 60);
316+
317+
let hours = format!("{:0>2}", duration.num_hours() % 24);
336318

337319
let days = duration.num_days().to_string();
338320

339-
format!("{}d {}:{}:{}", days, hours, minutes, seconds)
321+
format!(
322+
"{}d {}:{}:{}.{}",
323+
days, hours, minutes, seconds, milliseconds
324+
)
340325
}

0 commit comments

Comments
 (0)