mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-27 18:56:30 +00:00
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
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -74,7 +74,8 @@ use crate::stats::{Collector, Reporter, REPORTER};
|
|||||||
|
|
||||||
#[tokio::main(worker_threads = 4)]
|
#[tokio::main(worker_threads = 4)]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
env_logger::init();
|
env_logger::builder().format_timestamp_micros().init();
|
||||||
|
|
||||||
info!("Welcome to PgCat! Meow. (Version {})", VERSION);
|
info!("Welcome to PgCat! Meow. (Version {})", VERSION);
|
||||||
|
|
||||||
if !query_router::QueryRouter::setup() {
|
if !query_router::QueryRouter::setup() {
|
||||||
@@ -307,34 +308,18 @@ async fn main() {
|
|||||||
///
|
///
|
||||||
/// * `duration` - A duration of time
|
/// * `duration` - A duration of time
|
||||||
fn format_duration(duration: &chrono::Duration) -> String {
|
fn format_duration(duration: &chrono::Duration) -> String {
|
||||||
let seconds = {
|
let milliseconds = format!("{:0>3}", duration.num_milliseconds() % 1000);
|
||||||
let seconds = duration.num_seconds() % 60;
|
|
||||||
if seconds < 10 {
|
|
||||||
format!("0{}", seconds)
|
|
||||||
} else {
|
|
||||||
format!("{}", seconds)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let minutes = {
|
let seconds = format!("{:0>2}", duration.num_seconds() % 60);
|
||||||
let minutes = duration.num_minutes() % 60;
|
|
||||||
if minutes < 10 {
|
|
||||||
format!("0{}", minutes)
|
|
||||||
} else {
|
|
||||||
format!("{}", minutes)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let hours = {
|
let minutes = format!("{:0>2}", duration.num_minutes() % 60);
|
||||||
let hours = duration.num_hours() % 24;
|
|
||||||
if hours < 10 {
|
let hours = format!("{:0>2}", duration.num_hours() % 24);
|
||||||
format!("0{}", hours)
|
|
||||||
} else {
|
|
||||||
format!("{}", hours)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let days = duration.num_days().to_string();
|
let days = duration.num_days().to_string();
|
||||||
|
|
||||||
format!("{}d {}:{}:{}", days, hours, minutes, seconds)
|
format!(
|
||||||
|
"{}d {}:{}:{}.{}",
|
||||||
|
days, hours, minutes, seconds, milliseconds
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user