Add rocksdb logging integration with tracing.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-09-23 21:38:56 +00:00 committed by strawberry
parent c569881b08
commit a8d5cf9651
2 changed files with 18 additions and 1 deletions

View file

@ -10,7 +10,7 @@ use conduit::{debug, error, info, utils::time::rfc2822_from_seconds, warn, Err,
use rocksdb::{
backup::{BackupEngine, BackupEngineOptions},
perf::get_memory_usage_stats,
AsColumnFamilyRef, BoundColumnFamily, Cache, ColumnFamilyDescriptor, DBCommon, DBWithThreadMode, Env,
AsColumnFamilyRef, BoundColumnFamily, Cache, ColumnFamilyDescriptor, DBCommon, DBWithThreadMode, Env, LogLevel,
MultiThreaded, Options,
};
@ -279,6 +279,21 @@ pub(crate) fn repair(db_opts: &Options, path: &PathBuf) -> Result<()> {
Ok(())
}
#[tracing::instrument(skip_all, name = "rocksdb")]
pub(crate) fn handle_log(level: LogLevel, msg: &str) {
let msg = msg.trim();
if msg.starts_with("Options") {
return;
}
match level {
LogLevel::Header | LogLevel::Debug => debug!("{msg}"),
LogLevel::Error | LogLevel::Fatal => error!("{msg}"),
LogLevel::Info => debug!("{msg}"),
LogLevel::Warn => warn!("{msg}"),
};
}
impl Drop for Engine {
#[cold]
fn drop(&mut self) {

View file

@ -191,6 +191,8 @@ fn set_logging_defaults(opts: &mut Options, config: &Config) {
if config.rocksdb_log_stderr {
opts.set_stderr_logger(rocksdb_log_level, "rocksdb");
} else {
opts.set_callback_logger(rocksdb_log_level, &super::engine::handle_log);
}
}