diff --git a/subsys/shell/modules/kernel_service.c b/subsys/shell/modules/kernel_service.c index 10fbdad2e7..b5c1136dfd 100644 --- a/subsys/shell/modules/kernel_service.c +++ b/subsys/shell/modules/kernel_service.c @@ -16,6 +16,9 @@ #include #include #include +#if defined(CONFIG_LOG_RUNTIME_FILTERING) +#include +#endif static int cmd_kernel_version(const struct shell *shell, size_t argc, char **argv) @@ -240,6 +243,41 @@ static int cmd_kernel_sleep(const struct shell *sh, return 0; } +#if defined(CONFIG_LOG_RUNTIME_FILTERING) +static int cmd_kernel_log_level_set(const struct shell *sh, + size_t argc, char **argv) +{ + ARG_UNUSED(argc); + ARG_UNUSED(argv); + int err = 0; + + uint8_t severity = shell_strtoul(argv[2], 10, &err); + + if (err) { + shell_error(sh, "Unable to parse log severity (err %d)", err); + + return err; + } + + if (severity > LOG_LEVEL_DBG) { + shell_error(sh, "Invalid log level: %d", severity); + shell_help(sh); + return SHELL_CMD_HELP_PRINTED; + } + + int source_id = log_source_id_get(argv[1]); + + /* log_filter_set() takes an int16_t for the source ID */ + if (source_id < 0) { + shell_error(sh, "Unable to find log source: %s", argv[1]); + } + + log_filter_set(NULL, 0, (int16_t)source_id, severity); + + return 0; +} +#endif + #if defined(CONFIG_REBOOT) static int cmd_kernel_reboot_warm(const struct shell *shell, size_t argc, char **argv) @@ -285,6 +323,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_kernel, SHELL_CMD(uptime, NULL, "Kernel uptime.", cmd_kernel_uptime), SHELL_CMD(version, NULL, "Kernel version.", cmd_kernel_version), SHELL_CMD_ARG(sleep, NULL, "ms", cmd_kernel_sleep, 2, 0), +#if defined(CONFIG_LOG_RUNTIME_FILTERING) + SHELL_CMD_ARG(log-level, NULL, " ", + cmd_kernel_log_level_set, 3, 0), +#endif SHELL_SUBCMD_SET_END /* Array terminated. */ ); diff --git a/tests/bluetooth/shell/prj.conf b/tests/bluetooth/shell/prj.conf index 2780fb334f..58d31802a4 100644 --- a/tests/bluetooth/shell/prj.conf +++ b/tests/bluetooth/shell/prj.conf @@ -52,3 +52,6 @@ CONFIG_BT_ISO_BROADCASTER=y CONFIG_BT_ISO_SYNC_RECEIVER=y CONFIG_BT_ISO_CENTRAL=y CONFIG_BT_ISO_PERIPHERAL=y + +# See commit message for usage +CONFIG_LOG_RUNTIME_FILTERING=y