Skip to content

Commit

Permalink
feat: Support /dev/mdev.log
Browse files Browse the repository at this point in the history
Fixes: #16
  • Loading branch information
lu-zero committed Dec 31, 2024
1 parent 10449ca commit 186af98
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/bin/mdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,29 @@ impl Opt {
Ok(())
}

fn setup_log(&self) {
fn setup_log(&self) -> anyhow::Result<()> {
use tracing_subscriber::{fmt, prelude::*};
if self.daemon && !self.foreground && !self.syslog {
return;
return Ok(());
}

let registry = setup_log(self.verbose);
let fmt_layer = fmt::layer().with_target(false);

let mdev_log = Path::new("/dev/mdev.log");
let file_log = if mdev_log.is_file() {
let log = std::fs::OpenOptions::new().append(true).open(mdev_log)?;
let fmt_layer = fmt::layer()
.with_target(false)
.with_ansi(false)
.with_writer(log);
Some(fmt_layer)
} else {
None
};

let registry = registry.with(file_log);

if self.syslog {
// SAFETY: They are strings that do not contain a null byte
let identity = std::env::args()
Expand All @@ -284,6 +298,8 @@ impl Opt {
} else {
registry.with(fmt_layer).init();
}

Ok(())
}
}

Expand All @@ -304,7 +320,7 @@ fn main() -> anyhow::Result<()> {

let opt = Opt::parse();

opt.setup_log();
opt.setup_log()?;

if opt.scan {
opt.run_scan(&conf)?;
Expand Down

0 comments on commit 186af98

Please sign in to comment.