Shell: kernel: Add runtime log filtering command
Use `kernel log-level modulename severity` Also enable it for the Bluetooth Shell. Then one can compile-in a lot of BT modules like so: CONFIG_BT_DEBUG_HCI_CORE=y CONFIG_BT_DEBUG_L2CAP=y CONFIG_BT_DEBUG_ATT=y CONFIG_BT_DEBUG_GATT=y And at runtime select only, e.g. GATT kernel log-level bt_hci_core 0 kernel log-level bt_l2cap 0 kernel log-level bt_att 0 And then re-enable L2CAP if needed later kernel log-level bt_l2cap 4 And so on.. Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
This commit is contained in:
parent
a0ce235d9b
commit
76f74344a8
|
@ -16,6 +16,9 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <kernel_internal.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(CONFIG_LOG_RUNTIME_FILTERING)
|
||||
#include <zephyr/logging/log_ctrl.h>
|
||||
#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, "<module name> <severity (0-4)>",
|
||||
cmd_kernel_log_level_set, 3, 0),
|
||||
#endif
|
||||
SHELL_SUBCMD_SET_END /* Array terminated. */
|
||||
);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue