1 /*
2  * Copyright (c) 2018 Nordic Semiconductor ASA
3  * Copyright (c) 2021 Intel Corporation
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <zephyr/logging/log.h>
9 #include <zephyr/logging/log_ctrl.h>
10 #include <zephyr/logging/log_output.h>
11 #include <zephyr/logging/log_output_dict.h>
12 #include <zephyr/sys/__assert.h>
13 #include <zephyr/sys/util.h>
14 
log_dict_output_msg_process(const struct log_output * output,struct log_msg * msg,uint32_t flags)15 void log_dict_output_msg_process(const struct log_output *output,
16 				 struct log_msg *msg, uint32_t flags)
17 {
18 	struct log_dict_output_normal_msg_hdr_t output_hdr;
19 	void *source = (void *)log_msg_get_source(msg);
20 
21 	/* Keep sync with header in struct log_msg */
22 	output_hdr.type = MSG_NORMAL;
23 	output_hdr.domain = msg->hdr.desc.domain;
24 	output_hdr.level = msg->hdr.desc.level;
25 	output_hdr.package_len = msg->hdr.desc.package_len;
26 	output_hdr.data_len = msg->hdr.desc.data_len;
27 	output_hdr.timestamp = msg->hdr.timestamp;
28 
29 	output_hdr.source = (source != NULL) ? log_source_id(source) : 0U;
30 
31 	log_output_write(output->func, (uint8_t *)&output_hdr, sizeof(output_hdr),
32 			 (void *)output->control_block->ctx);
33 
34 	size_t len;
35 	uint8_t *data = log_msg_get_package(msg, &len);
36 
37 	if (len > 0U) {
38 		log_output_write(output->func, data, len, (void *)output->control_block->ctx);
39 	}
40 
41 	data = log_msg_get_data(msg, &len);
42 	if (len > 0U) {
43 		log_output_write(output->func, data, len, (void *)output->control_block->ctx);
44 	}
45 
46 	log_output_flush(output);
47 }
48 
log_dict_output_dropped_process(const struct log_output * output,uint32_t cnt)49 void log_dict_output_dropped_process(const struct log_output *output, uint32_t cnt)
50 {
51 	struct log_dict_output_dropped_msg_t msg;
52 
53 	msg.type = MSG_DROPPED_MSG;
54 	msg.num_dropped_messages = MIN(cnt, 9999);
55 
56 	log_output_write(output->func, (uint8_t *)&msg, sizeof(msg),
57 			 (void *)output->control_block->ctx);
58 }
59