forked from diem/diem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[safety-rules] Refactor for improved logging
By placing each of these calls into a guarded mode, I can cleanly extract entry, success, and failure. This will also help with the removal of monitoring / logging code within the actual protocol logic. Closes: diem#5052 Approved by: zekun000
- Loading branch information
1 parent
aa7d989
commit dfeae11
Showing
5 changed files
with
225 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) The Libra Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use libra_logger::StructuredLogEntry; | ||
|
||
pub fn safety_log(entry: LogEntry, event: LogEvent) -> StructuredLogEntry { | ||
StructuredLogEntry::new_named("safety_rules", entry.as_str()) | ||
.data(LogField::Event.as_str(), event.as_str()) | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum LogEntry { | ||
ConsensusState, | ||
ConstructAndSignVote, | ||
Initialize, | ||
SignProposal, | ||
SignTimeout, | ||
} | ||
|
||
impl LogEntry { | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
LogEntry::ConsensusState => "consensus_state", | ||
LogEntry::ConstructAndSignVote => "construct_and_sign_vote", | ||
LogEntry::Initialize => "initialize", | ||
LogEntry::SignProposal => "sign_proposal", | ||
LogEntry::SignTimeout => "sign_timeout", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum LogEvent { | ||
Error, | ||
Request, | ||
Success, | ||
} | ||
|
||
impl LogEvent { | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
LogEvent::Error => "error", | ||
LogEvent::Request => "request", | ||
LogEvent::Success => "success", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum LogField { | ||
Event, | ||
Message, | ||
Round, | ||
} | ||
|
||
impl LogField { | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
LogField::Event => "event", | ||
LogField::Message => "message", | ||
LogField::Round => "round", | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters