mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 10:53:25 +00:00
Move kcmdline parsing out of OSTD
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
397ce9652f
commit
5ea366bced
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user