Skip to content

Commit 921180c

Browse files
committed
Add configuration for heartbeat verbosity
1 parent 5aeff29 commit 921180c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

crates/amalthea/src/socket/heartbeat.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
*
66
*/
77

8-
use log::debug;
9-
use log::trace;
10-
use log::warn;
11-
128
use crate::socket::socket::Socket;
139

1410
/// Structure used for heartbeat messages
@@ -24,25 +20,34 @@ impl Heartbeat {
2420

2521
/// Listen for heartbeats; does not return
2622
pub fn listen(&self) {
23+
// Should we make it quiet by default in debug builds?
24+
let quiet = std::env::var("ARK_HEARTBEAT_QUIET").is_ok();
25+
2726
loop {
28-
debug!("Listening for heartbeats");
27+
if !quiet {
28+
log::trace!("Listening for heartbeats");
29+
}
30+
2931
let mut msg = zmq::Message::new();
3032
if let Err(err) = self.socket.recv(&mut msg) {
31-
warn!("Error receiving heartbeat: {}", err);
33+
log::warn!("Error receiving heartbeat: {}", err);
3234

3335
// Wait 1s before trying to receive another heartbeat. This
3436
// keeps us from flooding the logs when recv() isn't working.
3537
std::thread::sleep(std::time::Duration::from_secs(1));
3638
continue;
37-
} else {
38-
trace!("Heartbeat message: {:?}", msg);
39+
}
40+
if !quiet {
41+
log::trace!("Heartbeat message: {:?}", msg);
3942
}
4043

4144
// Echo the message right back!
4245
if let Err(err) = self.socket.send(msg) {
43-
warn!("Error replying to heartbeat: {}", err);
44-
} else {
45-
trace!("Heartbeat message replied");
46+
log::warn!("Error replying to heartbeat: {}", err);
47+
continue;
48+
}
49+
if !quiet {
50+
log::trace!("Heartbeat message replied");
4651
}
4752
}
4853
}

0 commit comments

Comments
 (0)