Skip to content

Commit 389993b

Browse files
authored
Accurate log messages (#425)
1 parent ba5243b commit 389993b

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/pool.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ impl ConnectionPool {
641641
{
642642
Ok(conn) => conn,
643643
Err(err) => {
644-
error!("Banning instance {:?}, error: {:?}", address, err);
644+
error!(
645+
"Connection checkout error for instance {:?}, error: {:?}",
646+
address, err
647+
);
645648
self.ban(address, BanReason::FailedCheckout, Some(client_stats));
646649
address.stats.error();
647650
client_stats.idle();
@@ -717,7 +720,7 @@ impl ConnectionPool {
717720
// Health check failed.
718721
Err(err) => {
719722
error!(
720-
"Banning instance {:?} because of failed health check, {:?}",
723+
"Failed health check on instance {:?}, error: {:?}",
721724
address, err
722725
);
723726
}
@@ -726,7 +729,7 @@ impl ConnectionPool {
726729
// Health check timed out.
727730
Err(err) => {
728731
error!(
729-
"Banning instance {:?} because of health check timeout, {:?}",
732+
"Health check timeout on instance {:?}, error: {:?}",
730733
address, err
731734
);
732735
}
@@ -748,13 +751,16 @@ impl ConnectionPool {
748751
return;
749752
}
750753

754+
error!("Banning instance {:?}, reason: {:?}", address, reason);
755+
751756
let now = chrono::offset::Utc::now().naive_utc();
752757
let mut guard = self.banlist.write();
753-
error!("Banning {:?}", address);
758+
754759
if let Some(client_info) = client_info {
755760
client_info.ban_error();
756761
address.stats.error();
757762
}
763+
758764
guard[address.shard].insert(address.clone(), (reason, now));
759765
}
760766

src/server.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,10 @@ impl Server {
705705
Ok(())
706706
}
707707
Err(err) => {
708-
error!("Terminating server because of: {:?}", err);
708+
error!(
709+
"Terminating server {:?} because of: {:?}",
710+
self.address, err
711+
);
709712
self.bad = true;
710713
Err(err)
711714
}
@@ -720,7 +723,10 @@ impl Server {
720723
let mut message = match read_message(&mut self.stream).await {
721724
Ok(message) => message,
722725
Err(err) => {
723-
error!("Terminating server because of: {:?}", err);
726+
error!(
727+
"Terminating server {:?} because of: {:?}",
728+
self.address, err
729+
);
724730
self.bad = true;
725731
return Err(err);
726732
}
@@ -1135,14 +1141,18 @@ impl Drop for Server {
11351141
_ => debug!("Dirty shutdown"),
11361142
};
11371143

1138-
// Should not matter.
1139-
self.bad = true;
1140-
11411144
let now = chrono::offset::Utc::now().naive_utc();
11421145
let duration = now - self.connected_at;
11431146

1147+
let message = if self.bad {
1148+
"Server connection terminated"
1149+
} else {
1150+
"Server connection closed"
1151+
};
1152+
11441153
info!(
1145-
"Server connection closed {:?}, session duration: {}",
1154+
"{} {:?}, session duration: {}",
1155+
message,
11461156
self.address,
11471157
crate::format_duration(&duration)
11481158
);

0 commit comments

Comments
 (0)