From a0d193a25ef340f67b823cb1327599a10beaf1b4 Mon Sep 17 00:00:00 2001 From: Max Niederman Date: Mon, 22 Apr 2024 21:53:13 -0700 Subject: [PATCH] feat(cli): default to info-level logging and add timestamps --- packages/centipede/src/main.rs | 16 +++++++++------- packages/centipede_control/src/lib.rs | 8 ++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/centipede/src/main.rs b/packages/centipede/src/main.rs index 1deb5a4..b6d3719 100644 --- a/packages/centipede/src/main.rs +++ b/packages/centipede/src/main.rs @@ -1,12 +1,8 @@ use std::{ - error::Error, - path::PathBuf, - sync::{ + env, error::Error, path::PathBuf, sync::{ atomic::{AtomicBool, Ordering}, mpsc, Arc, - }, - thread, - time::{Duration, SystemTime}, + }, thread, time::{Duration, SystemTime} }; use centipede_control::{Controller, IncomingMessage}; @@ -30,7 +26,11 @@ struct Opt { } fn main() -> Result<()> { - pretty_env_logger::init(); + if env::var_os("RUST_LOG").is_none() { + env::set_var("RUST_LOG", "info"); + } + + pretty_env_logger::init_timed(); let opt = ::parse(); log::debug!("opt: {:#?}", opt); @@ -129,6 +129,8 @@ fn main() -> Result<()> { s.spawn(move || worker_loop(worker, i, shutdown, None)); } + log::info!("spawned {} worker threads", opt.workers); + let router_configurator = router.configurator(); loop { if shutdown.load(Ordering::Relaxed) { diff --git a/packages/centipede_control/src/lib.rs b/packages/centipede_control/src/lib.rs index d904203..a4fae03 100644 --- a/packages/centipede_control/src/lib.rs +++ b/packages/centipede_control/src/lib.rs @@ -593,12 +593,8 @@ impl Controller { (mut state, Content::Heartbeat) => { log::debug!( - "received heartbeat from `{peer}` at {time}", - peer = BASE64_STANDARD.encode(message.sender()), - time = now - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap_or_default() - .as_secs() + "received heartbeat from `{peer}`", + peer = BASE64_STANDARD.encode(message.sender()) ); // Delay expiration of the remote address.