Use LOG_TARGET in consensus related crates (#12875)

* Use shared LOG_TARGET in consensus related crates
* Rename target from "afg" to "grandpa"
This commit is contained in:
Davide Galassi
2022-12-14 14:56:17 +01:00
committed by GitHub
parent 3e0a1904b7
commit 391adaf443
31 changed files with 343 additions and 247 deletions
+17 -8
View File
@@ -93,10 +93,12 @@ use std::{
time::Duration,
};
const LOG_TARGET: &str = "grandpa";
// utility logging macro that takes as first argument a conditional to
// decide whether to log under debug or info level (useful to restrict
// logging under initial sync).
macro_rules! afg_log {
macro_rules! grandpa_log {
($condition:expr, $($msg: expr),+ $(,)?) => {
{
let log_level = if $condition {
@@ -105,7 +107,7 @@ macro_rules! afg_log {
log::Level::Info
};
log::log!(target: "afg", log_level, $($msg),+);
log::log!(target: LOG_TARGET, log_level, $($msg),+);
}
};
}
@@ -803,10 +805,11 @@ where
);
let voter_work = voter_work.map(|res| match res {
Ok(()) => error!(target: "afg",
Ok(()) => error!(
target: LOG_TARGET,
"GRANDPA voter future has concluded naturally, this should be unreachable."
),
Err(e) => error!(target: "afg", "GRANDPA voter error: {}", e),
Err(e) => error!(target: LOG_TARGET, "GRANDPA voter error: {}", e),
});
// Make sure that `telemetry_task` doesn't accidentally finish and kill grandpa.
@@ -871,7 +874,7 @@ where
let metrics = match prometheus_registry.as_ref().map(Metrics::register) {
Some(Ok(metrics)) => Some(metrics),
Some(Err(e)) => {
debug!(target: "afg", "Failed to register metrics: {:?}", e);
debug!(target: LOG_TARGET, "Failed to register metrics: {:?}", e);
None
},
None => None,
@@ -913,7 +916,12 @@ where
/// state. This method should be called when we know that the authority set
/// has changed (e.g. as signalled by a voter command).
fn rebuild_voter(&mut self) {
debug!(target: "afg", "{}: Starting new voter with set ID {}", self.env.config.name(), self.env.set_id);
debug!(
target: LOG_TARGET,
"{}: Starting new voter with set ID {}",
self.env.config.name(),
self.env.set_id
);
let maybe_authority_id =
local_authority_id(&self.env.voters, self.env.config.keystore.as_ref());
@@ -974,7 +982,8 @@ where
// Repoint shared_voter_state so that the RPC endpoint can query the state
if self.shared_voter_state.reset(voter.voter_state()).is_none() {
info!(target: "afg",
info!(
target: LOG_TARGET,
"Timed out trying to update shared GRANDPA voter state. \
RPC endpoints may return stale data."
);
@@ -1043,7 +1052,7 @@ where
Ok(())
},
VoterCommand::Pause(reason) => {
info!(target: "afg", "Pausing old validator set: {}", reason);
info!(target: LOG_TARGET, "Pausing old validator set: {}", reason);
// not racing because old voter is shut down.
self.env.update_voter_set_state(|voter_set_state| {