zephyr/subsys/logging/log_output_dict.c

75 lines
1.8 KiB
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
* Copyright (c) 2021 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <logging/log.h>
#include <logging/log_ctrl.h>
#include <logging/log_output.h>
#include <logging/log_output_dict.h>
#include <sys/__assert.h>
#include <sys/util.h>
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);
}
void log_dict_output_msg2_process(const struct log_output *output,
struct log_msg2 *msg, uint32_t flags)
{
struct log_dict_output_normal_msg_hdr_t output_hdr;
void *source = (void *)log_msg2_get_source(msg);
/* Keep sync with header in struct log_msg2 */
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),
(void *)output);
size_t len;
uint8_t *data = log_msg2_get_package(msg, &len);
if (len > 0U) {
buffer_write(output->func, data, len, (void *)output);
}
data = log_msg2_get_data(msg, &len);
if (len > 0U) {
buffer_write(output->func, data, len, (void *)output);
}
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),
(void *)output);
}