From 1595b3ad6cb73a4dfb4ca009db4398a79fdf5f08 Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Tue, 27 Jul 2021 17:09:13 -0700 Subject: [PATCH] kata-shell: add loglevel command Syntax: loglevel [off, info, debug, warn, error, trace] Change-Id: I6b480626783cd4bf069a7741d7f4670e96c967b6 GitOrigin-RevId: 527aefa1f2b00d17f7f703d43923463b660caa7e --- .../DebugConsole/kata-shell/src/lib.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apps/system/components/DebugConsole/kata-shell/src/lib.rs b/apps/system/components/DebugConsole/kata-shell/src/lib.rs index cc3935a..9b4c584 100644 --- a/apps/system/components/DebugConsole/kata-shell/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-shell/src/lib.rs @@ -76,6 +76,7 @@ fn dispatch_command(cmdline: &str, output: &mut dyn io::Write) { "add" => add_command(&mut args, output), "echo" => echo_command(cmdline, output), "clear" => clear_command(output), + "loglevel" => loglevel_command(&mut args, output), "ps" => ps_command(), "test_alloc" => test_alloc_command(output), @@ -108,6 +109,27 @@ 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, +) -> Result<(), CommandError> { + if let Some(level) = args.nth(0) { + use log::LevelFilter; + match level { + "off" => log::set_max_level(LevelFilter::Off), + "debug" => log::set_max_level(LevelFilter::Debug), + "info" => log::set_max_level(LevelFilter::Info), + "error" => log::set_max_level(LevelFilter::Error), + "trace" => log::set_max_level(LevelFilter::Trace), + "warn" => log::set_max_level(LevelFilter::Warn), + _ => writeln!(output, "Unknown log level {}", level)?, + } + } + Ok(writeln!(output, "{}", log::max_level())?) +} + /// Implements a "ps" command that dumps seL4 scheduler state to the console. fn ps_command() -> Result<(), CommandError> { extern "C" {