1 /* 2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HI_DEBUG_DEFINE_H 16 #define HI_DEBUG_DEFINE_H 17 18 #include "hi_type.h" 19 20 #ifdef __cplusplus 21 #if __cplusplus 22 extern "C" { 23 #endif 24 #endif /* End of #ifdef __cplusplus */ 25 26 /* 27 * @brief log level type. 28 */ 29 typedef enum hiLOG_LEVEL_E { 30 HI_LOG_LEVEL_VERBOSE = -1, // assigned to verbose -1 because need to be compatible with previous version 31 HI_LOG_LEVEL_DEBUG = 0, 32 HI_LOG_LEVEL_INFO, 33 HI_LOG_LEVEL_WARN, 34 HI_LOG_LEVEL_ERR, 35 HI_LOG_LEVEL_FATAL, 36 HI_LOG_LEVEL_BUTT 37 } HI_LOG_LEVEL_E; 38 39 typedef HI_VOID (*HI_OUTPUT_FUNC)(const HI_CHAR *fmt, ...); 40 41 /** 42 * @brief set enabled log level, logs with equal or higher level than enabled will be output 43 * @param[in] enLevel : HI_LOG_LEVEL_E: enabled level 44 * @retval 0 success,others failed 45 */ 46 HI_S32 HI_LOG_SetEnabledLevel(HI_LOG_LEVEL_E enLevel); 47 48 /** 49 * @brief use this API to set log output function instead of 'printf' 50 * @param[in] pFunc : HI_OUTPUT_FUNC: output function implements by user 51 * @retval 0 success,others failed 52 */ 53 HI_S32 HI_LOG_SetOutputFunc(HI_OUTPUT_FUNC pFunc); 54 55 /** 56 * @brief output log 57 * @param[in] pszModName : HI_CHAR*: module name 58 * @param[in] enLevel : HI_LOG_LEVEL_E: log level 59 * @param[in] pszFmt : HI_CHAR*: log content, accept multi-parameters 60 * @retval 0 success,others failed 61 */ 62 #ifdef ENABLE_LOG 63 HI_S32 HI_LOG_Printf(const HI_CHAR *pszModName, HI_LOG_LEVEL_E enLevel, const HI_CHAR *pszFmt, ...) 64 __attribute__((format(printf, 3, 4))); 65 #else 66 #define HI_LOG_Printf(pszModName, enLevel, pszFmt, ...) 67 #endif 68 #ifdef __cplusplus 69 #if __cplusplus 70 } 71 #endif 72 #endif /* __cplusplus */ 73 74 #endif /* HI_DEBUG_DEFINE_H */ 75