DebugConsole: add features to set initial logging level

Add features to control the log level used before reaching the shell
prompt (where the "loglevel" command can be used to control log
filtering).  The default log level is Info. LOG_DEBUG forces it to
Debug. LOG_TRACE forces it to Trace (max).

Change-Id: Ic55eaf3cd08fc101c53319b5a45a2c7de6f94a66
GitOrigin-RevId: 5500ac5d65186773d5304a75d03295e09b2e9a63
This commit is contained in:
Sam Leffler 2022-06-27 18:53:46 +00:00
parent c9f36f4da8
commit 4ca13e9088
2 changed files with 17 additions and 4 deletions

View File

@ -5,6 +5,12 @@ authors = ["Matt Harvey <mattharvey@google.com>"]
edition = "2021"
description = "Kata OS DebugConsole"
[features]
default = []
# Log level is Info unless LOG_DEBUG or LOG_TRACE are specified
LOG_DEBUG = []
LOG_TRACE = []
[dependencies]
panic-halt = "0.2.0"
kata-io = { path = "../kata-io" }

View File

@ -13,6 +13,16 @@
use core::slice;
use kata_os_common::camkes::Camkes;
use log::LevelFilter;
// NB: this controls filtering log messages from all components because
// they are setup to send all log messges to the console.
#[cfg(feature = "LOG_DEBUG")]
const INIT_LOG_LEVEL: LevelFilter = LevelFilter::Debug;
#[cfg(feature = "LOG_TRACE")]
const INIT_LOG_LEVEL: LevelFilter = LevelFilter::Trace;
#[cfg(not(any(feature = "LOG_DEBUG", feature = "LOG_TRACE")))]
const INIT_LOG_LEVEL: LevelFilter = LevelFilter::Info;
extern "C" {
static cpio_archive: *const u8; // CPIO archive of built-in files
@ -24,10 +34,7 @@ static mut CAMKES: Camkes = Camkes::new("DebugConsole");
pub unsafe extern "C" fn pre_init() {
const HEAP_SIZE: usize = 16 * 1024;
static mut HEAP_MEMORY: [u8; HEAP_SIZE] = [0; HEAP_SIZE];
CAMKES.pre_init(
log::LevelFilter::Debug,
&mut HEAP_MEMORY,
);
CAMKES.pre_init(INIT_LOG_LEVEL, &mut HEAP_MEMORY);
}
/// Entry point for DebugConsole. Runs the shell with UART IO.