1 /*
2  * Copyright (c) 2019 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef ZEPHYR_LOG_BACKEND_STD_H_
7 #define ZEPHYR_LOG_BACKEND_STD_H_
8 
9 #include <zephyr/logging/log_msg.h>
10 #include <zephyr/logging/log_output.h>
11 #include <zephyr/kernel.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * @brief Logger backend interface for forwarding to standard backend
19  * @defgroup log_backend_std Logger backend standard interface
20  * @ingroup logger
21  * @{
22  */
23 
log_backend_std_get_flags(void)24 static inline uint32_t log_backend_std_get_flags(void)
25 {
26 	uint32_t flags = (LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP);
27 
28 	if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
29 		flags |= LOG_OUTPUT_FLAG_COLORS;
30 	}
31 
32 	if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
33 		flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
34 	}
35 
36 	if (IS_ENABLED(CONFIG_LOG_THREAD_ID_PREFIX)) {
37 		flags |= LOG_OUTPUT_FLAG_THREAD;
38 	}
39 
40 	return flags;
41 }
42 
43 /** @brief Put a standard logger backend into panic mode.
44  *
45  * @param output	Log output instance.
46  */
47 static inline void
log_backend_std_panic(const struct log_output * const output)48 log_backend_std_panic(const struct log_output *const output)
49 {
50 	log_output_flush(output);
51 }
52 
53 /** @brief Report dropped messages to a standard logger backend.
54  *
55  * @param output	Log output instance.
56  * @param cnt		Number of dropped messages.
57  */
58 static inline void
log_backend_std_dropped(const struct log_output * const output,uint32_t cnt)59 log_backend_std_dropped(const struct log_output *const output, uint32_t cnt)
60 {
61 	log_output_dropped_process(output, cnt);
62 }
63 
64 /**
65  * @}
66  */
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 #endif /* ZEPHYR_LOG_BACKEND_STD_H_ */
73