logging: Add support to backends to switch log format at runtime.
Adding mechanism to all the backends to switch the logging formats at runtime while leveraging the function pointer table based upon the Kconfigs which also cleans up the logging backend design. Also demonstrate the working API with the changes to syst sample. Clean up Kconfig for backends and add a standard template to generate the Kconfigs for logging formats to be used by all backends. Signed-off-by: Aastha Grover <aastha.grover@intel.com>
This commit is contained in:
parent
9fcbace639
commit
c0d7e10beb
13 changed files with 226 additions and 105 deletions
|
@ -72,6 +72,7 @@ static int data_out_drop_mode(uint8_t *data, size_t length, void *ctx);
|
|||
|
||||
static int char_out_drop_mode(uint8_t data);
|
||||
static int line_out_drop_mode(void);
|
||||
static uint32_t log_format_current = CONFIG_LOG_BACKEND_RTT_OUTPUT_DEFAULT;
|
||||
|
||||
static inline bool is_sync_mode(void)
|
||||
{
|
||||
|
@ -257,7 +258,7 @@ LOG_OUTPUT_DEFINE(log_output_rtt,
|
|||
static void put(const struct log_backend *const backend,
|
||||
struct log_msg *msg)
|
||||
{
|
||||
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ?
|
||||
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_OUTPUT_SYST) ?
|
||||
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
|
||||
|
||||
log_backend_std_put(&log_output_rtt, flag, msg);
|
||||
|
@ -297,7 +298,7 @@ static void sync_string(const struct log_backend *const backend,
|
|||
struct log_msg_ids src_level, uint32_t timestamp,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ?
|
||||
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_OUTPUT_SYST) ?
|
||||
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
|
||||
|
||||
log_backend_std_sync_string(&log_output_rtt, flag, src_level,
|
||||
|
@ -308,7 +309,7 @@ static void sync_hexdump(const struct log_backend *const backend,
|
|||
struct log_msg_ids src_level, uint32_t timestamp,
|
||||
const char *metadata, const uint8_t *data, uint32_t length)
|
||||
{
|
||||
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ?
|
||||
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_OUTPUT_SYST) ?
|
||||
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
|
||||
|
||||
log_backend_std_sync_hexdump(&log_output_rtt, flag, src_level,
|
||||
|
@ -320,9 +321,15 @@ static void process(const struct log_backend *const backend,
|
|||
{
|
||||
uint32_t flags = log_backend_std_get_flags();
|
||||
|
||||
flags |= IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ? LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
|
||||
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
|
||||
|
||||
log_output_msg2_process(&log_output_rtt, &msg->log, flags);
|
||||
log_output_func(&log_output_rtt, &msg->log, flags);
|
||||
}
|
||||
|
||||
static int format_set(const struct log_backend *const backend, uint32_t log_type)
|
||||
{
|
||||
log_format_current = log_type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct log_backend_api log_backend_rtt_api = {
|
||||
|
@ -335,6 +342,7 @@ const struct log_backend_api log_backend_rtt_api = {
|
|||
.panic = panic,
|
||||
.init = log_backend_rtt_init,
|
||||
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
|
||||
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
|
||||
};
|
||||
|
||||
LOG_BACKEND_DEFINE(log_backend_rtt, log_backend_rtt_api, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue