Move kcmdline parsing out of OSTD

This commit is contained in:
Zhang Junyang
2024-12-31 14:29:49 +08:00
committed by Tate, Hongliang Tian
parent 397ce9652f
commit 5ea366bced
5 changed files with 20 additions and 27 deletions

View File

@ -12,7 +12,7 @@ use core::str::FromStr;
use log::{LevelFilter, Metadata, Record};
use spin::Once;
use crate::boot::{boot_info, kcmdline::ModuleArg};
use crate::boot::BOOT_TIME_INFO;
static LOGGER: Logger = Logger::new();
@ -82,16 +82,15 @@ pub(crate) fn init() {
}
fn get_log_level() -> Option<LevelFilter> {
let module_args = boot_info().kernel_cmdline.get_module_args("ostd")?;
let kcmdline = BOOT_TIME_INFO.get().unwrap().kernel_cmdline;
// Although OSTD is agnostic of the parsing of the kernel command line,
// the logger assumes that it follows the Linux kernel command line format.
// We search for the `ostd.log_level=ARGUMENT` pattern in string.
let value = kcmdline
.split(' ')
.find(|arg| arg.starts_with("ostd.log_level="))
.map(|arg| arg.split('=').last().unwrap_or_default())?;
let value = {
let value = module_args.iter().find_map(|arg| match arg {
ModuleArg::KeyVal(name, value) if name.as_bytes() == "log_level".as_bytes() => {
Some(value)
}
_ => None,
})?;
value.as_c_str().to_str().ok()?
};
LevelFilter::from_str(value).ok()
}