Skip to content

Commit

Permalink
Merge pull request #884 from h4sh3d/refactor/change-ssm-log-levels
Browse files Browse the repository at this point in the history
Logs: move syncer state transitions logs to debug level
  • Loading branch information
TheCharlatan authored Dec 27, 2022
2 parents 1e9417f + e59becf commit cdfb149
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub trait StateMachineExecutor<
let event = Event::with(endpoints, runtime.identity(), source, request);
let sm_display = sm.to_string();
let sm_name = sm.name();
let sm_log_level = sm.log_level();
if let Some(new_sm) = sm.next(event, runtime)? {
let new_sm_display = new_sm.to_string();
// relegate state transitions staying the same to debug
Expand All @@ -38,7 +39,8 @@ pub trait StateMachineExecutor<
new_sm.bright_green_bold()
);
} else {
info!(
log!(
new_sm.log_level(),
"{} state transition {} -> {}",
new_sm.name(),
sm_display.red_bold(),
Expand All @@ -47,7 +49,8 @@ pub trait StateMachineExecutor<
}
Ok(Some(new_sm))
} else {
info!(
log!(
sm_log_level,
"{} state machine ended {} -> {}",
sm_name,
sm_display.red_bold(),
Expand All @@ -70,7 +73,13 @@ where
where
Self: Sized;

/// Return the display name of the state machine
fn name(&self) -> String;

/// Return the log level to use for state transitions. Info by default
fn log_level(&self) -> log::Level {
log::Level::Info
}
}

/// Event changing state machine state, consisting of a certain P2P or RPC `request` sent from some
Expand Down
4 changes: 4 additions & 0 deletions src/farcasterd/syncer_state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl StateMachine<Runtime, Error> for SyncerStateMachine {
fn name(&self) -> String {
"Syncer".to_string()
}

fn log_level(&self) -> log::Level {
log::Level::Debug
}
}

pub struct SyncerStateMachineExecutor {}
Expand Down

0 comments on commit cdfb149

Please sign in to comment.