Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: silence verbose logs when performing a transaction [WPB-14953] #815

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions crypto-ffi/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,20 +954,38 @@ struct CoreCryptoLoggerWrapper {
logger: std::sync::Arc<dyn CoreCryptoLogger>,
}

impl CoreCryptoLoggerWrapper {
fn adjusted_log_level(&self, metadata: &Metadata) -> Level {
match (metadata.level(), metadata.target()) {
// increase log level for refinery_core::traits since they are too verbose in transactions
(level, "refinery_core::traits") if level >= Level::Info => Level::Debug,
(level, "refinery_core::traits::sync") if level >= Level::Info => Level::Debug,
(level, _) => level,
}
}
}

impl log::Log for CoreCryptoLoggerWrapper {
fn enabled(&self, _metadata: &Metadata) -> bool {
true
fn enabled(&self, metadata: &Metadata) -> bool {
log::max_level() >= self.adjusted_log_level(metadata)
}

fn log(&self, record: &Record) {
let kvs = record.key_values();
let mut visitor = KeyValueVisitor(BTreeMap::new());
let _ = kvs.visit(&mut visitor);

if !self.enabled(record.metadata()) {
return;
}
SimonThormeyer marked this conversation as resolved.
Show resolved Hide resolved

let message = format!("{}", record.args());
let context = serde_json::to_string(&visitor.0).ok();
self.logger
.log(CoreCryptoLogLevel::from(&record.level()), message, context);
self.logger.log(
CoreCryptoLogLevel::from(&self.adjusted_log_level(record.metadata())),
message,
context,
);
}

fn flush(&self) {}
Expand Down
Loading