5
5
*
6
6
*/
7
7
8
- use log:: debug;
9
- use log:: trace;
10
- use log:: warn;
11
-
12
8
use crate :: socket:: socket:: Socket ;
13
9
14
10
/// Structure used for heartbeat messages
@@ -24,25 +20,34 @@ impl Heartbeat {
24
20
25
21
/// Listen for heartbeats; does not return
26
22
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
+
27
26
loop {
28
- debug ! ( "Listening for heartbeats" ) ;
27
+ if !quiet {
28
+ log:: trace!( "Listening for heartbeats" ) ;
29
+ }
30
+
29
31
let mut msg = zmq:: Message :: new ( ) ;
30
32
if let Err ( err) = self . socket . recv ( & mut msg) {
31
- warn ! ( "Error receiving heartbeat: {}" , err) ;
33
+ log :: warn!( "Error receiving heartbeat: {}" , err) ;
32
34
33
35
// Wait 1s before trying to receive another heartbeat. This
34
36
// keeps us from flooding the logs when recv() isn't working.
35
37
std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
36
38
continue ;
37
- } else {
38
- trace ! ( "Heartbeat message: {:?}" , msg) ;
39
+ }
40
+ if !quiet {
41
+ log:: trace!( "Heartbeat message: {:?}" , msg) ;
39
42
}
40
43
41
44
// Echo the message right back!
42
45
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" ) ;
46
51
}
47
52
}
48
53
}
0 commit comments