2021-04-03 03:54:53 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Nordic Semiconductor ASA
|
|
|
|
* Copyright (c) 2021 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 17:12:04 +08:00
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
#include <zephyr/logging/log_ctrl.h>
|
|
|
|
#include <zephyr/logging/log_output.h>
|
|
|
|
#include <zephyr/logging/log_output_dict.h>
|
|
|
|
#include <zephyr/sys/__assert.h>
|
|
|
|
#include <zephyr/sys/util.h>
|
2021-04-03 03:54:53 +08:00
|
|
|
|
|
|
|
static void buffer_write(log_output_func_t outf, uint8_t *buf, size_t len,
|
|
|
|
void *ctx)
|
|
|
|
{
|
|
|
|
int processed;
|
|
|
|
|
|
|
|
do {
|
|
|
|
processed = outf(buf, len, ctx);
|
|
|
|
len -= processed;
|
|
|
|
buf += processed;
|
|
|
|
} while (len != 0);
|
|
|
|
}
|
|
|
|
|
2022-06-21 17:51:38 +08:00
|
|
|
void log_dict_output_msg_process(const struct log_output *output,
|
|
|
|
struct log_msg *msg, uint32_t flags)
|
2021-04-03 03:54:53 +08:00
|
|
|
{
|
|
|
|
struct log_dict_output_normal_msg_hdr_t output_hdr;
|
2022-06-21 17:51:38 +08:00
|
|
|
void *source = (void *)log_msg_get_source(msg);
|
2021-04-03 03:54:53 +08:00
|
|
|
|
2022-06-21 17:51:38 +08:00
|
|
|
/* Keep sync with header in struct log_msg */
|
2021-04-03 03:54:53 +08:00
|
|
|
output_hdr.type = MSG_NORMAL;
|
|
|
|
output_hdr.domain = msg->hdr.desc.domain;
|
|
|
|
output_hdr.level = msg->hdr.desc.level;
|
|
|
|
output_hdr.package_len = msg->hdr.desc.package_len;
|
|
|
|
output_hdr.data_len = msg->hdr.desc.data_len;
|
|
|
|
output_hdr.timestamp = msg->hdr.timestamp;
|
|
|
|
|
|
|
|
output_hdr.source = (source != NULL) ?
|
|
|
|
(IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ?
|
|
|
|
log_dynamic_source_id(source) :
|
|
|
|
log_const_source_id(source)) :
|
|
|
|
0U;
|
|
|
|
|
|
|
|
buffer_write(output->func, (uint8_t *)&output_hdr, sizeof(output_hdr),
|
2023-12-04 23:23:57 +08:00
|
|
|
(void *)output->control_block->ctx);
|
2021-04-03 03:54:53 +08:00
|
|
|
|
|
|
|
size_t len;
|
2022-06-21 17:51:38 +08:00
|
|
|
uint8_t *data = log_msg_get_package(msg, &len);
|
2021-04-03 03:54:53 +08:00
|
|
|
|
|
|
|
if (len > 0U) {
|
2023-12-04 23:23:57 +08:00
|
|
|
buffer_write(output->func, data, len, (void *)output->control_block->ctx);
|
2021-04-03 03:54:53 +08:00
|
|
|
}
|
|
|
|
|
2022-06-21 17:51:38 +08:00
|
|
|
data = log_msg_get_data(msg, &len);
|
2021-04-03 03:54:53 +08:00
|
|
|
if (len > 0U) {
|
2023-12-04 23:23:57 +08:00
|
|
|
buffer_write(output->func, data, len, (void *)output->control_block->ctx);
|
2021-04-03 03:54:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log_output_flush(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_dict_output_dropped_process(const struct log_output *output, uint32_t cnt)
|
|
|
|
{
|
|
|
|
struct log_dict_output_dropped_msg_t msg;
|
|
|
|
|
|
|
|
msg.type = MSG_DROPPED_MSG;
|
|
|
|
msg.num_dropped_messages = MIN(cnt, 9999);
|
|
|
|
|
|
|
|
buffer_write(output->func, (uint8_t *)&msg, sizeof(msg),
|
2023-12-04 23:23:57 +08:00
|
|
|
(void *)output->control_block->ctx);
|
2021-04-03 03:54:53 +08:00
|
|
|
}
|