samples: logging: dictionary: Add support for runtime filtering

Extend sample with configuration which has shell on one UART and
UART dictionary based frontend on another. Shell commands can be used
to control runtime filtering of logging messages for the frontend and
shell backend.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2024-01-02 12:40:23 +01:00 committed by Carles Cufí
parent dc99da6a4f
commit 5062cef1f0
4 changed files with 54 additions and 1 deletions

View file

@ -11,6 +11,13 @@ This is a sample app which utilizes :ref:`dictionary-based logging <logging_guid
the UART backend. This is configured to output binary log data
in hexadecimal so it could be run in terminal.
There is also a configuration which shows how shell commands can be used to configure runtime
filtering of the logging messages for the frontend (in the same way as it is done for backends).
See ``log frontend`` set of commands and use ``log_rt_demo`` command to test the filtering.
Configuration with shell requires that board has two UART devices (one for the shell and one for
the UART dictionary based frontend).
Building and Running
********************

View file

@ -0,0 +1,16 @@
/*
* Copyright 2024 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,shell-uart = &uart1;
};
};
&uart1 {
status = "okay";
};

View file

@ -41,6 +41,22 @@ tests:
- CONFIG_LOG_FRONTEND=y
- CONFIG_LOG_FRONTEND_ONLY=y
- CONFIG_LOG_FRONTEND_DICT_UART=y
sample.logger.basic.dictionary.uart_frontend_rt:
build_only: true
tags: logging
platform_allow: nrf5340dk_nrf5340_cpuapp
integration_platforms:
- nrf5340dk_nrf5340_cpuapp
extra_configs:
- CONFIG_SHELL=y
- CONFIG_LOG_RUNTIME_FILTERING=y
- CONFIG_LOG_CMDS=y
- CONFIG_LOG_BACKEND_RTT=n
- CONFIG_LOG_BACKEND_UART=n
- CONFIG_UART_ASYNC_API=y
- CONFIG_UART_INTERRUPT_DRIVEN=n
- CONFIG_LOG_FRONTEND=y
- CONFIG_LOG_FRONTEND_DICT_UART=y
sample.logger.basic.dictionary.uart_int_frontend:
build_only: true
tags: logging

View file

@ -10,8 +10,9 @@
#include <string.h>
#include <zephyr/sys/printk.h>
#include <zephyr/logging/log.h>
#include <zephyr/shell/shell.h>
LOG_MODULE_REGISTER(hello_world, 4);
LOG_MODULE_REGISTER(hello_world, LOG_LEVEL_DBG);
static const char *hexdump_msg = "HEXDUMP! HEXDUMP@ HEXDUMP#";
@ -72,3 +73,16 @@ int main(void)
#endif
return 0;
}
static int rt_demo_cmd(const struct shell *sh, size_t argc, char **argv)
{
ARG_UNUSED(sh);
LOG_ERR("demo %s", argc > 1 ? argv[1] : "");
LOG_WRN("demo %s", argc > 1 ? argv[1] : "");
LOG_INF("demo %s", argc > 1 ? argv[1] : "");
LOG_DBG("demo %s", argc > 1 ? argv[1] : "");
return 0;
}
SHELL_CMD_REGISTER(log_rt_demo, NULL, "Command can be used to test runtime filtering", rt_demo_cmd);