Skip to content

Commit

Permalink
rdb: test logging improvements
Browse files Browse the repository at this point in the history
move rdb over to using mg_common logging functions, rather than its own
re-implementation. Also add a .gitignore for *.log so nextest doesn't
pollute the repo.

Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
  • Loading branch information
taspelund committed Nov 1, 2024
1 parent 5a862da commit 6f41d48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
1 change: 1 addition & 0 deletions rdb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.log
22 changes: 4 additions & 18 deletions rdb/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,25 +691,10 @@ impl Reaper {
#[cfg(test)]
mod test {
use crate::{db::Db, Path, Prefix};
use slog::{Drain, Logger};
use std::fs::File;
use std::io::Write;
use mg_common::log::*;
use std::net::IpAddr;
use std::str::FromStr;

pub fn init_file_logger(filename: &str) -> Logger {
build_logger(File::create(filename).expect("build logger"))
}

pub fn build_logger<W: Write + Send + 'static>(w: W) -> Logger {
let drain = slog_bunyan::new(w).build().fuse();
let drain = slog_async::Async::new(drain)
.chan_size(0x8000)
.build()
.fuse();
slog::Logger::root(drain, slog::o!())
}

pub fn check_prefix_path(
db: &Db,
prefix: &Prefix,
Expand Down Expand Up @@ -813,8 +798,9 @@ mod test {
let static_path1 = Path::from(static_key1);

// setup
let log = init_file_logger("rib.log");
let db_path = "rib.db".to_string();
std::fs::create_dir_all("/tmp").expect("create tmp dir");
let log = init_file_logger("/tmp/rib.log");
let db_path = "/tmp/rib.db".to_string();
let _ = std::fs::remove_dir_all(&db_path);
let db = Db::new(&db_path, log.clone()).expect("create db");

Expand Down

0 comments on commit 6f41d48

Please sign in to comment.