Skip to content

Commit 92a7058

Browse files
xtask: Install a simple logger
This currently doesn't do anything, but in the next commit ovmf-prebuilt will be used to download OVMF files, and that library uses the logger.
1 parent 92275d1 commit 92a7058

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fatfs = { version = "0.3.6", default-features = false, features = ["alloc", "std
1212
fs-err = "3.0.0"
1313
heck = "0.5.0"
1414
itertools = "0.13.0"
15+
log.workspace = true
1516
lzma-rs = "0.3.0"
1617
mbrman = "0.5.1"
1718
nix = { version = "0.29.0", default-features = false, features = ["fs"] }
@@ -24,5 +25,5 @@ sha2 = "0.10.6"
2425
syn = { version = "2.0.0", features = ["full"] }
2526
tar = "0.4.38"
2627
tempfile = "3.6.0"
27-
walkdir = "2.4.0"
2828
ureq = "2.8.0"
29+
walkdir = "2.4.0"

xtask/src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use arch::UefiArch;
1717
use cargo::{Cargo, CargoAction, Feature, Package, TargetTypes};
1818
use clap::Parser;
1919
use itertools::Itertools;
20+
use log::{LevelFilter, Metadata, Record};
2021
use opt::{Action, BuildOpt, ClippyOpt, CovOpt, DocOpt, Opt, QemuOpt, TpmVersion};
2122
use std::process::Command;
2223
use util::run_cmd;
@@ -322,9 +323,33 @@ fn has_cmd(target_cmd: &str) -> bool {
322323
run_cmd(cmd).is_ok()
323324
}
324325

326+
fn install_logger() {
327+
struct Logger;
328+
329+
impl log::Log for Logger {
330+
fn enabled(&self, _: &Metadata) -> bool {
331+
true
332+
}
333+
334+
fn log(&self, record: &Record) {
335+
println!("[{}] {}", record.level(), record.args());
336+
}
337+
338+
fn flush(&self) {}
339+
}
340+
341+
static LOGGER: Logger = Logger;
342+
343+
log::set_logger(&LOGGER)
344+
.map(|()| log::set_max_level(LevelFilter::Info))
345+
.unwrap();
346+
}
347+
325348
fn main() -> Result<()> {
326349
let opt = Opt::parse();
327350

351+
install_logger();
352+
328353
match &opt.action {
329354
Action::Build(build_opt) => build(build_opt),
330355
Action::CheckRaw(_) => check_raw::check_raw(),

0 commit comments

Comments
 (0)