1 /* 2 * Copyright 2022 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 17 #ifndef __MPP_LOG_H__ 18 #define __MPP_LOG_H__ 19 20 #include "rk_type.h" 21 #include "mpp_log_def.h" 22 23 /* 24 * _c function will add condition check 25 * _f function will add function name to the log 26 * _cf function will add both function name and condition check 27 */ 28 29 /* 30 * mpp runtime log system usage: 31 * mpp_logf is for fatal logging. For use when aborting 32 * mpp_loge is for error logging. For use with unrecoverable failures. 33 * mpp_logw is for warning logging. For use with recoverable failures. 34 * mpp_logi is for informational logging. 35 * mpp_logd is for debug logging. 36 * mpp_logv is for verbose logging 37 */ 38 39 #define mpp_logf(fmt, ...) _mpp_log_l(MPP_LOG_FATAL, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 40 #define mpp_loge(fmt, ...) _mpp_log_l(MPP_LOG_ERROR, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 41 #define mpp_logw(fmt, ...) _mpp_log_l(MPP_LOG_WARN, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 42 #define mpp_logi(fmt, ...) _mpp_log_l(MPP_LOG_INFO, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 43 #define mpp_logd(fmt, ...) _mpp_log_l(MPP_LOG_DEBUG, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 44 #define mpp_logv(fmt, ...) _mpp_log_l(MPP_LOG_VERBOSE, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 45 46 #define mpp_logf_f(fmt, ...) _mpp_log_l(MPP_LOG_FATAL, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 47 #define mpp_loge_f(fmt, ...) _mpp_log_l(MPP_LOG_ERROR, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 48 #define mpp_logw_f(fmt, ...) _mpp_log_l(MPP_LOG_WARN, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 49 #define mpp_logi_f(fmt, ...) _mpp_log_l(MPP_LOG_INFO, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 50 #define mpp_logd_f(fmt, ...) _mpp_log_l(MPP_LOG_DEBUG, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 51 #define mpp_logv_f(fmt, ...) _mpp_log_l(MPP_LOG_VERBOSE, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 52 53 #define mpp_logf_c(cond, fmt, ...) do { if (cond) mpp_logf(fmt, ## __VA_ARGS__); } while (0) 54 #define mpp_loge_c(cond, fmt, ...) do { if (cond) mpp_loge(fmt, ## __VA_ARGS__); } while (0) 55 #define mpp_logw_c(cond, fmt, ...) do { if (cond) mpp_logw(fmt, ## __VA_ARGS__); } while (0) 56 #define mpp_logi_c(cond, fmt, ...) do { if (cond) mpp_logi(fmt, ## __VA_ARGS__); } while (0) 57 #define mpp_logd_c(cond, fmt, ...) do { if (cond) mpp_logd(fmt, ## __VA_ARGS__); } while (0) 58 #define mpp_logv_c(cond, fmt, ...) do { if (cond) mpp_logv(fmt, ## __VA_ARGS__); } while (0) 59 60 #define mpp_logf_cf(cond, fmt, ...) do { if (cond) mpp_logf_f(fmt, ## __VA_ARGS__); } while (0) 61 #define mpp_loge_cf(cond, fmt, ...) do { if (cond) mpp_loge_f(fmt, ## __VA_ARGS__); } while (0) 62 #define mpp_logw_cf(cond, fmt, ...) do { if (cond) mpp_logw_f(fmt, ## __VA_ARGS__); } while (0) 63 #define mpp_logi_cf(cond, fmt, ...) do { if (cond) mpp_logi_f(fmt, ## __VA_ARGS__); } while (0) 64 #define mpp_logd_cf(cond, fmt, ...) do { if (cond) mpp_logd_f(fmt, ## __VA_ARGS__); } while (0) 65 #define mpp_logv_cf(cond, fmt, ...) do { if (cond) mpp_logv_f(fmt, ## __VA_ARGS__); } while (0) 66 67 /* 68 * mpp runtime log system usage: 69 * mpp_err is for error status message, it will print for sure. 70 * mpp_log is for important message like open/close/reset/flush, it will print too. 71 */ 72 73 #define mpp_log(fmt, ...) mpp_logi(fmt, ## __VA_ARGS__) 74 #define mpp_err(fmt, ...) mpp_loge(fmt, ## __VA_ARGS__) 75 76 #define mpp_log_f(fmt, ...) mpp_logi_f(fmt, ## __VA_ARGS__) 77 #define mpp_err_f(fmt, ...) mpp_loge_f(fmt, ## __VA_ARGS__) 78 79 #define mpp_log_c(cond, fmt, ...) do { if (cond) mpp_log(fmt, ## __VA_ARGS__); } while (0) 80 #define mpp_log_cf(cond, fmt, ...) do { if (cond) mpp_log_f(fmt, ## __VA_ARGS__); } while (0) 81 82 #ifdef __cplusplus 83 extern "C" { 84 #endif 85 86 void _mpp_log_l(int level, const char *tag, const char *fmt, const char *func, ...); 87 88 void mpp_set_log_level(int level); 89 int mpp_get_log_level(void); 90 91 /* deprecated function */ 92 void _mpp_log(const char *tag, const char *fmt, const char *func, ...); 93 void _mpp_err(const char *tag, const char *fmt, const char *func, ...); 94 95 #ifdef __cplusplus 96 } 97 #endif 98 99 #endif /*__MPP_LOG_H__*/ 100