From 4ca13e90889b5bd36ee8fe9fd9cea8a99474384e Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Mon, 27 Jun 2022 18:53:46 +0000 Subject: [PATCH] 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 --- .../DebugConsole/kata-debug-console/Cargo.toml | 6 ++++++ .../DebugConsole/kata-debug-console/src/run.rs | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/system/components/DebugConsole/kata-debug-console/Cargo.toml b/apps/system/components/DebugConsole/kata-debug-console/Cargo.toml index b1bc2a9..95f02f3 100644 --- a/apps/system/components/DebugConsole/kata-debug-console/Cargo.toml +++ b/apps/system/components/DebugConsole/kata-debug-console/Cargo.toml @@ -5,6 +5,12 @@ authors = ["Matt Harvey "] 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" } diff --git a/apps/system/components/DebugConsole/kata-debug-console/src/run.rs b/apps/system/components/DebugConsole/kata-debug-console/src/run.rs index f1dfdf6..be6f495 100644 --- a/apps/system/components/DebugConsole/kata-debug-console/src/run.rs +++ b/apps/system/components/DebugConsole/kata-debug-console/src/run.rs @@ -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.