AM263Px MCU+ SDK: ub_logging.h Source File

| AM263Px MCU+ SDK 26.00.00 |

ub_logging.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2023 Texas Instruments Incorporated
3 * Copyright (c) 2023 Excelfore Corporation (https://excelfore.com)
4 *
5 * All rights reserved not granted herein.
6 * Limited License.
7 *
8 * Texas Instruments Incorporated grants a world-wide, royalty-free,
9 * non-exclusive license under copyrights and patents it now or hereafter
10 * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
11 * this software subject to the terms herein. With respect to the foregoing patent
12 * license, such license is granted solely to the extent that any such patent is necessary
13 * to Utilize the software alone. The patent license shall not apply to any combinations which
14 * include this software, other than combinations with devices manufactured by or for TI ("TI Devices").
15 * No hardware patent is licensed hereunder.
16 *
17 * Redistributions must preserve existing copyright notices and reproduce this license (including the
18 * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
19 * in the documentation and/or other materials provided with the distribution
20 *
21 * Redistribution and use in binary form, without modification, are permitted provided that the following
22 * conditions are met:
23 *
24 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
25 * software provided in binary form.
26 * * any redistribution and use are licensed by TI for use only with TI Devices.
27 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
28 *
29 * If software source code is provided to you, modification and redistribution of the source code are permitted
30 * provided that the following conditions are met:
31 *
32 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
33 * TI for use only with TI Devices.
34 * * any redistribution and use of any object code compiled from the source code and any resulting derivative
35 * works, are licensed by TI for use only with TI Devices.
36 *
37 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
38 * promote products derived from this software without specific prior written permission.
39 *
40 * DISCLAIMER.
41 *
42 * THIS SOFTWARE IS PROVIDED BY TI AND TI"S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
43 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 * IN NO EVENT SHALL TI AND TI"S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
46 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48 * POSSIBILITY OF SUCH DAMAGE.
49 */
70 #ifndef UB_LOGGING_H_
71 #define UB_LOGGING_H_
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76
88 typedef int ub_dbgmsg_level_t;
89
90 #define UBL_NONE 0
91 #define UBL_FATAL 1
92 #define UBL_ERROR 2
93 #define UBL_WARN 3
94 #define UBL_INFO 4
95 #define UBL_INFOV 5
96 #define UBL_DEBUG 6
97 #define UBL_DEBUGV 7
98
99 #ifndef MAX_LOGMSG_CATEGORIES
100
101 #define MAX_LOGMSG_CATEGORIES 16
102 #endif
103
107 #define DBGMSG_LEVEL_MARK {"NON", "FTL", "ERR", "WRN", "INF", "IFV", "DBG", "DBV"}
108
113 #define UBL_TS_BIT_FIELDS 3 // bit0 and bit1
114
115 #ifndef UB_LOG_COMPILE_LEVEL
116 #define UB_LOG_COMPILE_LEVEL UBL_DEBUGV
117 #endif
118
119 #define UB_LOG_IS_COMPILED(level) (UB_LOG_COMPILE_LEVEL >= level)
120
121 #define UB_LOG_HELPER(level, tstype, ...) \
122 { \
123 if(ub_dlog_on(UB_LOGCAT, level) || ub_clog_on(UB_LOGCAT, level)) { \
124 char coutstr[UB_CHARS_IN_LINE]; \
125 (void)snprintf(coutstr, UB_CHARS_IN_LINE, __VA_ARGS__); \
126 (void)ub_log_print(UB_LOGCAT, tstype, level, coutstr); \
127 } \
128 }
129
130 #if UB_LOG_IS_COMPILED(UBL_DEBUGV)
131 #define UB_LOG_UBL_DEBUGV(...) UB_LOG_HELPER(UBL_DEBUGV, 0, __VA_ARGS__)
132 #define UB_TLOG_UBL_DEBUGV(...) UB_LOG_HELPER(UBL_DEBUGV, UB_LOGTSTYPE, __VA_ARGS__)
133 #else
134 #define UB_LOG_UBL_DEBUGV(...)
135 #define UB_TLOG_UBL_DEBUGV(...)
136 #endif
137
138 #if UB_LOG_IS_COMPILED(UBL_DEBUG)
139 #define UB_LOG_UBL_DEBUG(...) UB_LOG_HELPER(UBL_DEBUG, 0, __VA_ARGS__)
140 #define UB_TLOG_UBL_DEBUG(...) UB_LOG_HELPER(UBL_DEBUG, UB_LOGTSTYPE, __VA_ARGS__)
141 #else
142 #define UB_LOG_UBL_DEBUG(...)
143 #define UB_TLOG_UBL_DEBUG(...)
144 #endif
145
146 #if UB_LOG_IS_COMPILED(UBL_INFOV)
147 #define UB_LOG_UBL_INFOV(...) UB_LOG_HELPER(UBL_INFOV, 0, __VA_ARGS__)
148 #define UB_TLOG_UBL_INFOV(...) UB_LOG_HELPER(UBL_INFOV, UB_LOGTSTYPE, __VA_ARGS__)
149 #else
150 #define UB_LOG_UBL_INFOV(...)
151 #define UB_TLOG_UBL_INFOV(...)
152 #endif
153
154 #if UB_LOG_IS_COMPILED(UBL_INFO)
155 #define UB_LOG_UBL_INFO(...) UB_LOG_HELPER(UBL_INFO, 0, __VA_ARGS__)
156 #define UB_TLOG_UBL_INFO(...) UB_LOG_HELPER(UBL_INFO, UB_LOGTSTYPE, __VA_ARGS__)
157 #else
158 #define UB_LOG_UBL_INFO(...)
159 #define UB_TLOG_UBL_INFO(...)
160 #endif
161
162 #if UB_LOG_IS_COMPILED(UBL_WARN)
163 #define UB_LOG_UBL_WARN(...) UB_LOG_HELPER(UBL_WARN, 0, __VA_ARGS__)
164 #define UB_TLOG_UBL_WARN(...) UB_LOG_HELPER(UBL_WARN, UB_LOGTSTYPE, __VA_ARGS__)
165 #else
166 #define UB_LOG_UBL_WARN(...)
167 #define UB_TLOG_UBL_WARN(...)
168 #endif
169
170 #if UB_LOG_IS_COMPILED(UBL_ERROR)
171 #define UB_LOG_UBL_ERROR(...) UB_LOG_HELPER(UBL_ERROR, 0, __VA_ARGS__)
172 #define UB_TLOG_UBL_ERROR(...) UB_LOG_HELPER(UBL_ERROR, UB_LOGTSTYPE, __VA_ARGS__)
173 #else
174 #define UB_LOG_UBL_ERROR(...)
175 #define UB_TLOG_UBL_ERROR(...)
176 #endif
177
178 #if UB_LOG_IS_COMPILED(UBL_FATAL)
179 #define UB_LOG_UBL_FATAL(...) UB_LOG_HELPER(UBL_FATAL, 0, __VA_ARGS__)
180 #define UB_TLOG_UBL_FATAL(...) UB_LOG_HELPER(UBL_FATAL, UB_LOGTSTYPE, __VA_ARGS__)
181 #else
182 #define UB_LOG_UBL_FATAL(...)
183 #define UB_TLOG_UBL_FATAL(...)
184 #endif
185
186 #define UB_LOG_UBL_NONE(...)
187 #define UB_TLOG_UBL_NONE(...)
188
193 #define UBL_OVERRIDE_ISTR(x,y) ub_log_initstr_override(x,UBB_GETENV(y))
194
195 #ifdef PRINT_FORMAT_NO_WARNING
196
197 #define PRINT_FORMAT_ATTRIBUTE1
198 #define PRINT_FORMAT_ATTRIBUTE4
199 #else
200
201 #define PRINT_FORMAT_ATTRIBUTE1 __attribute__((format (printf, 1, 2)))
202 #define PRINT_FORMAT_ATTRIBUTE4 __attribute__((format (printf, 4, 5)))
203 #endif
204
211 void ub_console_debug_select_print(bool console, bool debug, const char *astr);
212
223 const char *ub_log_initstr_override(const char *ns, const char *os);
224
232 void ub_log_init(const char *istr);
233
242 int ub_log_add_category(const char *catstr);
243
253 int ub_log_print(int cat_index, int flags, ub_dbgmsg_level_t level, const char *astr);
254
259 bool ub_clog_on(int cat_index, ub_dbgmsg_level_t level);
260
265 bool ub_dlog_on(int cat_index, ub_dbgmsg_level_t level);
266
271 int ub_log_change(int cat_index, ub_dbgmsg_level_t clevel, ub_dbgmsg_level_t dlevel);
272
277 int ub_log_return(int cat_index);
278
283 void ub_log_flush(void);
284
285 #ifdef __cplusplus
286 }
287 #endif
288
289 #endif
290
ub_log_return
int ub_log_return(int cat_index)
return console log level and console log level to the previous status
ub_log_initstr_override
const char * ub_log_initstr_override(const char *ns, const char *os)
override 'istr' of ub_log_inig
ub_log_add_category
int ub_log_add_category(const char *catstr)
add a category of logging at the bottom of the index
ub_log_print
int ub_log_print(int cat_index, int flags, ub_dbgmsg_level_t level, const char *astr)
print log message
flags
uint8_t flags
Definition: hsmclient_msg.h:2
ub_log_flush
void ub_log_flush(void)
flush out messages on the both of cosole log and debug log
ub_clog_on
bool ub_clog_on(int cat_index, ub_dbgmsg_level_t level)
check if console log is enabled or not for the indicated cat_index and level
ub_dbgmsg_level_t
int ub_dbgmsg_level_t
This defines different logging levels.
Definition: ub_logging.h:88
ub_log_init
void ub_log_init(const char *istr)
initialize logging by a string
ub_log_change
int ub_log_change(int cat_index, ub_dbgmsg_level_t clevel, ub_dbgmsg_level_t dlevel)
change console log level to clevel, and debug log level to delevl
ub_dlog_on
bool ub_dlog_on(int cat_index, ub_dbgmsg_level_t level)
check if debug log is enabled or not for the indicated cat_index and level
ub_console_debug_select_print
void ub_console_debug_select_print(bool console, bool debug, const char *astr)
output to console out and debug out by selection