From db8cd7b7867c25ad935bcf89e5db6af3ad088555 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Tue, 22 May 2018 01:11:37 +0800 Subject: [PATCH] Use `LOG` env to set log level --- Makefile | 3 +++ src/io/mod.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 45611c8..6cd1215 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ # make run Run in debug # make run int=1 Run with interrupt info by QEMU # make run mode=release Run in release +# make run LOG=error Run with log level: error +# LOG = off | error | warn | info | debug | trace # make doc Generate docs # make asm Open the deassemble file of the last build # make clean Clean @@ -24,6 +26,7 @@ user_object_files := $(patsubst user/%.img, build/user/%.o, $(user_image_files)) qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio features := use_apic +LOG ?= debug link_user = 1 ifdef link_user diff --git a/src/io/mod.rs b/src/io/mod.rs index ae16a13..a2f734a 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -6,7 +6,14 @@ mod vga_writer; pub fn init() { static LOGGER: SimpleLogger = SimpleLogger; log::set_logger(&LOGGER).unwrap(); - log::set_max_level(LevelFilter::Debug); + log::set_max_level(match option_env!("LOG") { + Some("off") => LevelFilter::Off, + Some("error") => LevelFilter::Error, + Some("warn") => LevelFilter::Warn, + Some("info") => LevelFilter::Info, + Some("trace") => LevelFilter::Trace, + Some("debug") | _ => LevelFilter::Debug, + }); } macro_rules! print {