Skip to content

Commit

Permalink
fix: silence verbose logs when performing a transaction [WPB-14953]
Browse files Browse the repository at this point in the history
When creating transaction we also create an in-memory database as cache. When this
database is created all the schema migration are performed and logged at the info
level and they are very verbose. Silence them by mapping these logs to the Debug
level instead.
  • Loading branch information
typfel committed Dec 11, 2024
1 parent 20d47c1 commit b248ff0
Showing 1 changed file with 22 additions and 4 deletions.
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;
}

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

0 comments on commit b248ff0

Please sign in to comment.