AM263Px MCU+ SDK  10.01.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  char coutstr[UB_CHARS_IN_LINE]; \
124  (void)snprintf(coutstr, UB_CHARS_IN_LINE, __VA_ARGS__); \
125  (void)ub_log_print(UB_LOGCAT, tstype, level, coutstr); \
126  }
127 
128 #if UB_LOG_IS_COMPILED(UBL_DEBUGV)
129 #define UB_LOG_UBL_DEBUGV(...) UB_LOG_HELPER(UBL_DEBUGV, 0, __VA_ARGS__)
130 #define UB_TLOG_UBL_DEBUGV(...) UB_LOG_HELPER(UBL_DEBUGV, UB_LOGTSTYPE, __VA_ARGS__)
131 #else
132 #define UB_LOG_UBL_DEBUGV(...)
133 #define UB_TLOG_UBL_DEBUGV(...)
134 #endif
135 
136 #if UB_LOG_IS_COMPILED(UBL_DEBUG)
137 #define UB_LOG_UBL_DEBUG(...) UB_LOG_HELPER(UBL_DEBUG, 0, __VA_ARGS__)
138 #define UB_TLOG_UBL_DEBUG(...) UB_LOG_HELPER(UBL_DEBUG, UB_LOGTSTYPE, __VA_ARGS__)
139 #else
140 #define UB_LOG_UBL_DEBUG(...)
141 #define UB_TLOG_UBL_DEBUG(...)
142 #endif
143 
144 #if UB_LOG_IS_COMPILED(UBL_INFOV)
145 #define UB_LOG_UBL_INFOV(...) UB_LOG_HELPER(UBL_INFOV, 0, __VA_ARGS__)
146 #define UB_TLOG_UBL_INFOV(...) UB_LOG_HELPER(UBL_INFOV, UB_LOGTSTYPE, __VA_ARGS__)
147 #else
148 #define UB_LOG_UBL_INFOV(...)
149 #define UB_TLOG_UBL_INFOV(...)
150 #endif
151 
152 #if UB_LOG_IS_COMPILED(UBL_INFO)
153 #define UB_LOG_UBL_INFO(...) UB_LOG_HELPER(UBL_INFO, 0, __VA_ARGS__)
154 #define UB_TLOG_UBL_INFO(...) UB_LOG_HELPER(UBL_INFO, UB_LOGTSTYPE, __VA_ARGS__)
155 #else
156 #define UB_LOG_UBL_INFO(...)
157 #define UB_TLOG_UBL_INFO(...)
158 #endif
159 
160 #if UB_LOG_IS_COMPILED(UBL_WARN)
161 #define UB_LOG_UBL_WARN(...) UB_LOG_HELPER(UBL_WARN, 0, __VA_ARGS__)
162 #define UB_TLOG_UBL_WARN(...) UB_LOG_HELPER(UBL_WARN, UB_LOGTSTYPE, __VA_ARGS__)
163 #else
164 #define UB_LOG_UBL_WARN(...)
165 #define UB_TLOG_UBL_WARN(...)
166 #endif
167 
168 #if UB_LOG_IS_COMPILED(UBL_ERROR)
169 #define UB_LOG_UBL_ERROR(...) UB_LOG_HELPER(UBL_ERROR, 0, __VA_ARGS__)
170 #define UB_TLOG_UBL_ERROR(...) UB_LOG_HELPER(UBL_ERROR, UB_LOGTSTYPE, __VA_ARGS__)
171 #else
172 #define UB_LOG_UBL_ERROR(...)
173 #define UB_TLOG_UBL_ERROR(...)
174 #endif
175 
176 #if UB_LOG_IS_COMPILED(UBL_FATAL)
177 #define UB_LOG_UBL_FATAL(...) UB_LOG_HELPER(UBL_FATAL, 0, __VA_ARGS__)
178 #define UB_TLOG_UBL_FATAL(...) UB_LOG_HELPER(UBL_FATAL, UB_LOGTSTYPE, __VA_ARGS__)
179 #else
180 #define UB_LOG_UBL_FATAL(...)
181 #define UB_TLOG_UBL_FATAL(...)
182 #endif
183 
184 #define UB_LOG_UBL_NONE(...)
185 #define UB_TLOG_UBL_NONE(...)
186 
191 #define UBL_OVERRIDE_ISTR(x,y) ub_log_initstr_override(x,UBB_GETENV(y))
192 
193 #ifdef PRINT_FORMAT_NO_WARNING
194 
195 #define PRINT_FORMAT_ATTRIBUTE1
196 #define PRINT_FORMAT_ATTRIBUTE4
197 #else
198 
199 #define PRINT_FORMAT_ATTRIBUTE1 __attribute__((format (printf, 1, 2)))
200 #define PRINT_FORMAT_ATTRIBUTE4 __attribute__((format (printf, 4, 5)))
201 #endif
202 
209 void ub_console_debug_select_print(bool console, bool debug, const char *astr);
210 
221 const char *ub_log_initstr_override(const char *ns, const char *os);
222 
230 void ub_log_init(const char *istr);
231 
240 int ub_log_add_category(const char *catstr);
241 
251 int ub_log_print(int cat_index, int flags, ub_dbgmsg_level_t level, const char *astr);
252 
257 bool ub_clog_on(int cat_index, ub_dbgmsg_level_t level);
258 
263 bool ub_dlog_on(int cat_index, ub_dbgmsg_level_t level);
264 
269 int ub_log_change(int cat_index, ub_dbgmsg_level_t clevel, ub_dbgmsg_level_t dlevel);
270 
275 int ub_log_return(int cat_index);
276 
281 void ub_log_flush(void);
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif
288 
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