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