mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-08-07 08:14:12 +00:00
kata-logger: pass level through LoggerInterface and filter in DebugConsole
Components can reduce the number of rpc's if they set_max_level but by default pass everything and let the DebugConsole decide what is logged. With this the shell loglevel command now controls logging from all components. Change-Id: I72b77bbf02882ffdba0aaf0b9b88126bfd2e62a1 GitOrigin-RevId: d451e72cf67e41d6ee25ea2995098b5009cf8852
This commit is contained in:
parent
4043c8b5b7
commit
8ace3eb6f2
@ -15,7 +15,7 @@ impl log::Log for KataLogger {
|
|||||||
fn log(&self, record: &Record) {
|
fn log(&self, record: &Record) {
|
||||||
if self.enabled(record.metadata()) {
|
if self.enabled(record.metadata()) {
|
||||||
extern "C" {
|
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};
|
use bare_io::{Cursor, Write};
|
||||||
let mut buf = [0 as u8; MAX_MSG_LEN];
|
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
|
// NB: this releases the ref on buf held by the Cursor
|
||||||
let pos = cur.position() as usize;
|
let pos = cur.position() as usize;
|
||||||
logger_log(
|
logger_log(
|
||||||
|
record.level() as u8,
|
||||||
match CStr::from_bytes_with_nul(&buf[..pos]) {
|
match CStr::from_bytes_with_nul(&buf[..pos]) {
|
||||||
Ok(cstr) => cstr,
|
Ok(cstr) => cstr,
|
||||||
Err(_) => embedded_nul_cstr(&mut buf, record),
|
Err(_) => embedded_nul_cstr(&mut buf, record),
|
||||||
@ -85,7 +86,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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 {
|
unsafe {
|
||||||
// NB: this depends on msg pointing to the caller's array
|
// NB: this depends on msg pointing to the caller's array
|
||||||
MSGS.push(*(msg as *const [u8; MAX_MSG_LEN]));
|
MSGS.push(*(msg as *const [u8; MAX_MSG_LEN]));
|
||||||
|
@ -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.
|
// Set/display the max log level for the DebugConsole.
|
||||||
// TODO(sleffler): support setting the log level in other components
|
|
||||||
fn loglevel_command(
|
fn loglevel_command(
|
||||||
args: &mut dyn Iterator<Item = &str>,
|
args: &mut dyn Iterator<Item = &str>,
|
||||||
output: &mut dyn io::Write,
|
output: &mut dyn io::Write,
|
||||||
|
@ -9,3 +9,4 @@ edition = "2018"
|
|||||||
cstr_core = { version = "0.2.3", default-features = false }
|
cstr_core = { version = "0.2.3", default-features = false }
|
||||||
cty = "0.2.1"
|
cty = "0.2.1"
|
||||||
kata-io = { path = "../kata-io" }
|
kata-io = { path = "../kata-io" }
|
||||||
|
log = "0.4"
|
||||||
|
@ -19,11 +19,24 @@ extern "C" {
|
|||||||
|
|
||||||
// Console logging interface.
|
// Console logging interface.
|
||||||
#[no_mangle]
|
#[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) {
|
||||||
|
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 {};
|
let output: &mut dyn io::Write = &mut self::Tx {};
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = writeln!(output, "{}", CStr::from_ptr(msg).to_str().unwrap());
|
let _ = writeln!(output, "{}", CStr::from_ptr(msg).to_str().unwrap());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Rx {}
|
pub struct Rx {}
|
||||||
|
@ -15,7 +15,8 @@ use log::{info, trace};
|
|||||||
pub extern "C" fn pre_init() {
|
pub extern "C" fn pre_init() {
|
||||||
static KATA_LOGGER: KataLogger = KataLogger;
|
static KATA_LOGGER: KataLogger = KataLogger;
|
||||||
log::set_logger(&KATA_LOGGER).unwrap();
|
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
|
// TODO(sleffler): temp until we integrate with seL4
|
||||||
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
|
static mut HEAP_MEMORY: [u8; 16 * 1024] = [0; 16 * 1024];
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
procedure LoggerInterface {
|
procedure LoggerInterface {
|
||||||
void log(in string msg);
|
void log(in u_char level, in string msg);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user