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