diff --git a/apps/system/components/DebugConsole/kata-logger/src/lib.rs b/apps/system/components/DebugConsole/kata-logger/src/lib.rs index 46a5f49..22cb0b6 100644 --- a/apps/system/components/DebugConsole/kata-logger/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-logger/src/lib.rs @@ -15,7 +15,7 @@ impl log::Log for KataLogger { fn log(&self, record: &Record) { if self.enabled(record.metadata()) { extern "C" { - fn logger_log(msg: *const cstr_core::c_char); + fn logger_log(level: u8, msg: *const cstr_core::c_char); } use bare_io::{Cursor, Write}; let mut buf = [0 as u8; MAX_MSG_LEN]; @@ -55,6 +55,7 @@ impl log::Log for KataLogger { // NB: this releases the ref on buf held by the Cursor let pos = cur.position() as usize; logger_log( + record.level() as u8, match CStr::from_bytes_with_nul(&buf[..pos]) { Ok(cstr) => cstr, Err(_) => embedded_nul_cstr(&mut buf, record), @@ -85,7 +86,7 @@ mod tests { } #[no_mangle] - pub extern "C" fn logger_log(msg: *const cstr_core::c_char) { + pub extern "C" fn logger_log(_level: u8, msg: *const cstr_core::c_char) { unsafe { // NB: this depends on msg pointing to the caller's array MSGS.push(*(msg as *const [u8; MAX_MSG_LEN])); diff --git a/apps/system/components/DebugConsole/kata-shell/src/lib.rs b/apps/system/components/DebugConsole/kata-shell/src/lib.rs index e6e6927..ac5423e 100644 --- a/apps/system/components/DebugConsole/kata-shell/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-shell/src/lib.rs @@ -117,7 +117,6 @@ fn echo_command(cmdline: &str, output: &mut dyn io::Write) -> Result<(), Command } // Set/display the max log level for the DebugConsole. -// TODO(sleffler): support setting the log level in other components fn loglevel_command( args: &mut dyn Iterator, output: &mut dyn io::Write, diff --git a/apps/system/components/DebugConsole/kata-uart-client/Cargo.toml b/apps/system/components/DebugConsole/kata-uart-client/Cargo.toml index 10e4e1d..5abd0f1 100644 --- a/apps/system/components/DebugConsole/kata-uart-client/Cargo.toml +++ b/apps/system/components/DebugConsole/kata-uart-client/Cargo.toml @@ -9,3 +9,4 @@ edition = "2018" cstr_core = { version = "0.2.3", default-features = false } cty = "0.2.1" kata-io = { path = "../kata-io" } +log = "0.4" diff --git a/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs b/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs index 9f0c152..0f25d25 100644 --- a/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs @@ -19,10 +19,23 @@ extern "C" { // Console logging interface. #[no_mangle] -pub extern "C" fn logger_log(msg: *const cstr_core::c_char) { - let output: &mut dyn io::Write = &mut self::Tx {}; - unsafe { - let _ = writeln!(output, "{}", CStr::from_ptr(msg).to_str().unwrap()); +pub extern "C" fn logger_log(level: u8, msg: *const cstr_core::c_char) { + use log::Level; + // TODO(sleffler): seems like this should be try_from? + let l = match level { + x if x == Level::Error as u8 => Level::Error, + x if x == Level::Warn as u8 => Level::Warn, + x if x == Level::Info as u8 => Level::Info, + x if x == Level::Debug as u8 => Level::Debug, + x if x == Level::Trace as u8 => Level::Trace, + _ => { return }, // TODO(sleffler): accept or not? + }; + if l <= log::max_level() { + // TODO(sleffler): is the uart driver ok w/ multiple writers? + let output: &mut dyn io::Write = &mut self::Tx {}; + unsafe { + let _ = writeln!(output, "{}", CStr::from_ptr(msg).to_str().unwrap()); + } } } diff --git a/apps/system/components/ProcessManager/kata-proc-component/src/run.rs b/apps/system/components/ProcessManager/kata-proc-component/src/run.rs index c45dc88..b72ce24 100644 --- a/apps/system/components/ProcessManager/kata-proc-component/src/run.rs +++ b/apps/system/components/ProcessManager/kata-proc-component/src/run.rs @@ -15,7 +15,8 @@ use log::{info, trace}; pub extern "C" fn pre_init() { static KATA_LOGGER: KataLogger = KataLogger; log::set_logger(&KATA_LOGGER).unwrap(); - log::set_max_level(log::LevelFilter::Debug); + // NB: set to max; the LoggerInterface will filter + log::set_max_level(log::LevelFilter::Trace); // TODO(sleffler): temp until we integrate with seL4 static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024]; diff --git a/apps/system/interfaces/LoggerInterface.camkes b/apps/system/interfaces/LoggerInterface.camkes index 3de7032..48ec4d4 100644 --- a/apps/system/interfaces/LoggerInterface.camkes +++ b/apps/system/interfaces/LoggerInterface.camkes @@ -1,3 +1,3 @@ procedure LoggerInterface { - void log(in string msg); + void log(in u_char level, in string msg); };