1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2018-08-25     armink       the first version
9  */
10 
11 #ifndef _ULOG_H_
12 #define _ULOG_H_
13 
14 #include <rtthread.h>
15 #include "ulog_def.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /*
22  * ulog init and deint
23  */
24 int ulog_init(void);
25 int ulog_async_init(void);
26 void ulog_output_lock_enabled(rt_bool_t enabled);
27 void ulog_deinit(void);
28 
29 /*
30  * output different level log by LOG_X API
31  *
32  * NOTE: The `LOG_TAG` and `LOG_LVL` must be defined before including the <ulog.h> when you want to use LOG_X API.
33  *
34  * #define LOG_TAG              "example"
35  * #define LOG_LVL              LOG_LVL_DBG
36  * #include <ulog.h>
37  *
38  * Then you can using LOG_X API to output log
39  *
40  * LOG_D("this is a debug log!");
41  * LOG_E("this is a error log!");
42  */
43 #define LOG_E(...)                      ulog_e(LOG_TAG, __VA_ARGS__)
44 #define LOG_W(...)                      ulog_w(LOG_TAG, __VA_ARGS__)
45 #define LOG_I(...)                      ulog_i(LOG_TAG, __VA_ARGS__)
46 #define LOG_D(...)                      ulog_d(LOG_TAG, __VA_ARGS__)
47 #define LOG_RAW(...)                    ulog_raw(__VA_ARGS__)
48 #define LOG_HEX(name, width, buf, size) ulog_hex(name, width, buf, size)
49 
50 /*
51  * backend register and unregister
52  */
53 rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool_t support_color);
54 rt_err_t ulog_backend_unregister(ulog_backend_t backend);
55 rt_err_t ulog_backend_set_filter(ulog_backend_t backend, ulog_backend_filter_t filter);
56 ulog_backend_t ulog_backend_find(const char *name);
57 
58 #ifdef ULOG_USING_FILTER
59 /*
60  * log filter setting
61  */
62 int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level);
63 rt_uint32_t ulog_tag_lvl_filter_get(const char *tag);
64 rt_slist_t *ulog_tag_lvl_list_get(void);
65 void ulog_global_filter_lvl_set(rt_uint32_t level);
66 rt_uint32_t ulog_global_filter_lvl_get(void);
67 void ulog_global_filter_tag_set(const char *tag);
68 const char *ulog_global_filter_tag_get(void);
69 void ulog_global_filter_kw_set(const char *keyword);
70 const char *ulog_global_filter_kw_get(void);
71 #endif /* ULOG_USING_FILTER */
72 
73 /*
74  * flush all backends's log
75  */
76 void ulog_flush(void);
77 
78 #ifdef ULOG_USING_ASYNC_OUTPUT
79 /*
80  * asynchronous output API
81  */
82 void ulog_async_output(void);
83 void ulog_async_output_enabled(rt_bool_t enabled);
84 rt_err_t ulog_async_waiting_log(rt_int32_t time);
85 #endif
86 
87 /*
88  * dump the hex format data to log
89  */
90 void ulog_hexdump(const char *tag, rt_size_t width, const rt_uint8_t *buf, rt_size_t size, ...);
91 
92 /*
93  * Another log output API. This API is more difficult to use than LOG_X API.
94  */
95 void ulog_voutput(rt_uint32_t level, const char *tag, rt_bool_t newline, const rt_uint8_t *hex_buf,
96      rt_size_t hex_size, rt_size_t hex_width, rt_base_t hex_addr, const char *format, va_list args);
97 void ulog_output(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, ...);
98 void ulog_raw(const char *format, ...);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* _ULOG_H_ */
105