Skip to content

Commit

Permalink
feat(cli): default to info-level logging and add timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
max-niederman committed Apr 23, 2024
1 parent 4dbe326 commit a0d193a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 9 additions & 7 deletions packages/centipede/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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 = <Opt as clap::Parser>::parse();
log::debug!("opt: {:#?}", opt);
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions packages/centipede_control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,8 @@ impl<R: Rng + CryptoRng> Controller<R> {

(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.
Expand Down

0 comments on commit a0d193a

Please sign in to comment.