xref: /OK3568_Linux_fs/external/rockit/tgi/sdk/include/rt_log.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2018 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * author: martin.cheng@rock-chips.com
17  *   date: 20180704
18  */
19 
20 #ifndef INCLUDE_RT_BASE_RT_LOG_H_
21 #define INCLUDE_RT_BASE_RT_LOG_H_
22 
23 #include "rt_header.h"  // NOLINT
24 #include <stdarg.h>
25 #include <string>
26 
27 #ifndef LOG_TAG
28 #define LOG_TAG NULL
29 #endif
30 
31 #define RT_LOG_PRINT      0   /* print                                */
32 #define RT_LOG_FATAL      1   /* fatal error                          */
33 #define RT_LOG_ERR        2   /* error conditions                     */
34 #define RT_LOG_WARN       3   /* warning conditions                   */
35 #define RT_LOG_INFO       4   /* informational                        */
36 #define RT_LOG_DEBUG      5   /* debug-level messages                 */
37 #define RT_LOG_VERBOSE    6   /* verbose                              */
38 
39 #define LOG_LEVEL         RT_LOG_WARN
40 #define LOG_FLAG          0
41 
42 //! super macro.
43 #define RT_LOGD_IF(condition, format, ...) if (condition > 0) LOG_TRACE(RT_LOG_DEBUG, format, ##__VA_ARGS__)
44 #define RT_LOGE_IF(condition, format, ...) if (condition > 0) LOG_ERROR(RT_LOG_ERR, format, ##__VA_ARGS__)
45 
46 //! super macro.
47 #define RT_LOGP(format, ...) LOG_ERROR(RT_LOG_PRINT, format, ##__VA_ARGS__)
48 #define RT_LOGF(format, ...) LOG_ERROR(RT_LOG_FATAL, format, ##__VA_ARGS__)
49 #define RT_LOGE(format, ...) LOG_ERROR(RT_LOG_ERR, format, ##__VA_ARGS__)
50 #define RT_LOGW(format, ...) LOG_TRACE(RT_LOG_WARN, format, ##__VA_ARGS__)
51 #define RT_LOGI(format, ...) LOG_TRACE(RT_LOG_INFO, format, ##__VA_ARGS__)
52 #define RT_LOGD(format, ...) LOG_TRACE(RT_LOG_DEBUG, format, ##__VA_ARGS__)
53 #define RT_LOGV(format, ...) LOG_TRACE(RT_LOG_VERBOSE, format, ##__VA_ARGS__)
54 
55 //! super macro.
56 #define LOG_TRACE(level, fmt, ...) \
57         rt_log(level, LOG_TAG, fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
58 #define LOG_ERROR(level, fmt, ...) \
59         rt_err(level, LOG_TAG, fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)
60 
61 //! log function marcro.
62 // external api
63 #define RT_LOG_API_ENTER()   RT_LOGD_IF(LOG_FLAG, "%s called enter", __FUNCTION__)
64 #define RT_LOG_API_LEAVE()   RT_LOGD_IF(LOG_FLAG, "%s called leave", __FUNCTION__)
65 #define RT_LOG_API_CALLED()  RT_LOGD_IF(LOG_FLAG, "%s called", __FUNCTION__)
66 
67 // internal func
68 #define RT_LOG_FUNC_ENTER()  RT_LOGD_IF(LOG_FLAG, "%s enter", __FUNCTION__)
69 #define RT_LOG_FUNC_LEAVE()  RT_LOGD_IF(LOG_FLAG, "%s leave", __FUNCTION__)
70 #define RT_LOG_FUNC_CALLED() RT_LOGD_IF(LOG_FLAG, "%s called", __FUNCTION__)
71 
72 // construct/destruct
73 #define RT_LOG_CONSTRUCT_IN(thiz)    RT_LOGD_IF(LOG_FLAG, "%s(%p) construct", __FUNCTION__, thiz)
74 #define RT_LOG_CONSTRUCT_DONE(thiz)  RT_LOGD_IF(LOG_FLAG, "%s(%p) construct ok", __FUNCTION__, thiz)
75 #define RT_LOG_DESTRUCT_IN(thiz)     RT_LOGD_IF(LOG_FLAG, "%s(%p) destructor", __FUNCTION__, thiz)
76 #define RT_LOG_DESTRUCT_DONE(thiz)   RT_LOGD_IF(LOG_FLAG, "%s(%p) destructor ok", __FUNCTION__, thiz)
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 INT32 rt_get_log_level();
83 void  rt_set_log_level(INT32 level);
84 
85 void rt_log(INT32 level, const char *tag, const char *fmt, const char *fname,
86                             const UINT16 row, ...);
87 void rt_err(INT32 level, const char *tag, const char *fmt, const char *fname,
88                             const UINT16 row, ...);
89 void rt_log_va(INT32 level, const char *tag, const char *fmt, const char *fname,
90                             const UINT16 row, va_list args);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 #endif  // INCLUDE_RT_BASE_RT_LOG_H_
96