1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 /** 17 * @defgroup bsl_log 18 * @ingroup bsl 19 * @brief log module 20 */ 21 22 #ifndef BSL_LOG_H 23 #define BSL_LOG_H 24 25 #include <stdint.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /** 32 * @ingroup bsl_log 33 * 34 * Audit log level 35 */ 36 #define BSL_LOG_LEVEL_SEC 0U 37 38 /** 39 * @ingroup bsl_log 40 * 41 * Emergency log level 42 */ 43 #define BSL_LOG_LEVEL_FATAL 1U 44 45 /** 46 * @ingroup bsl_log 47 * 48 * Error log level 49 */ 50 #define BSL_LOG_LEVEL_ERR 2U 51 52 /** 53 * @ingroup bsl_log 54 * 55 * Warning log level 56 */ 57 #define BSL_LOG_LEVEL_WARN 3U 58 59 /** 60 * @ingroup bsl_log 61 * 62 * Information log level 63 */ 64 #define BSL_LOG_LEVEL_INFO 4U 65 66 /** 67 * @ingroup bsl_log 68 * 69 * Debug log level 70 */ 71 #define BSL_LOG_LEVEL_DEBUG 5U 72 73 /** 74 * @ingroup bsl_log 75 * 76 * HiTLS version string 77 */ 78 #ifndef OPENHITLS_VERSION_S 79 #define OPENHITLS_VERSION_S "openHiTLS 0.2.1 20 May 2025" 80 #endif 81 82 #ifndef OPENHITLS_VERSION_I 83 #define OPENHITLS_VERSION_I 0x0020001fULL 84 #endif 85 86 #define HITLS_VERSION_LEN 150 87 88 /** 89 * @ingroup bsl_log 90 * @brief Obtain the openHiTLS version string. 91 * 92 * @attention The length of the received version string must be greater than or equal to HITLS_VERSION_LEN. 93 * @param version [OUT] openHiTLS current version string. 94 * @param versionLen [IN/OUT] String length of the current openHiTLS version. 95 * @retval #BSL_SUCCESS, if success. 96 * @retval #BSL_LOG_ERR_MEMCPY, memory copy failure. 97 */ 98 int32_t BSL_LOG_GetVersion(char *version, uint32_t *versionLen); 99 100 /** 101 * @ingroup bsl_log 102 * @brief Obtain the openHiTLS version number. 103 * 104 * @retval openHiTLS version number. 105 */ 106 uint64_t BSL_LOG_GetVersionNum(void); 107 108 /** 109 * @ingroup bsl_log 110 * @brief Binlog type, other types can be extended. 111 */ 112 #define BSL_LOG_BINLOG_TYPE_RUN 0x01 113 114 /** 115 * @ingroup bsl_log 116 * @brief Fixed-length callback type of binlogs. 117 * 118 * The function format of this type cannot contain %s, the number of parameters is less than four, add 0s. 119 * More than four parameters must be called multiple times. 120 */ 121 typedef void (*BSL_LOG_BinLogFixLenFunc)(uint32_t logId, uint32_t logLevel, uint32_t logType, 122 void *format, void *para1, void *para2, void *para3, void *para4); 123 124 /** 125 * @ingroup bsl_log 126 * @brief Callback type for variable-length binlogs. 127 * 128 * This type function format contains only one %s, If no %s exists, use BSL_LOG_BinLogFixLenFunc type. 129 * If there are more than one %s, call the interface multiple times. 130 */ 131 typedef void (*BSL_LOG_BinLogVarLenFunc)(uint32_t logId, uint32_t logLevel, uint32_t logType, 132 void *format, void *para); 133 134 /** 135 * @ingroup bsl_log 136 * @brief Register the parameter type of the binlog callback function. 137 */ 138 typedef struct { 139 BSL_LOG_BinLogFixLenFunc fixLenFunc; /**< 4 parameter callback */ 140 BSL_LOG_BinLogVarLenFunc varLenFunc; /**< 1 parameter callback */ 141 } BSL_LOG_BinLogFuncs; 142 143 /** 144 * @ingroup bsl_log 145 * @brief Set the fixed-length and variable-length callback function for binlogs. 146 * 147 * @attention The input parameter can be NULL. 148 * @param funcs [IN] Callback function pointer collection of the binlog. 149 * The parameter cannot be null, but the member of the structure can be null. 150 * @retval #BSL_SUCCESS. 151 */ 152 int32_t BSL_LOG_RegBinLogFunc(const BSL_LOG_BinLogFuncs *funcs); 153 154 /** 155 * @ingroup bsl_log 156 * @brief Set the level of binlogs. 157 * 158 * @attention The level must be valid. 159 * @param level [IN] Level of the binlogs. The valid values are BSL_LOG_LEVEL_SEC, BSL_LOG_LEVEL_FATAL, 160 * BSL_LOG_LEVEL_ERR, BSL_LOG_LEVEL_WARN, BSL_LOG_LEVEL_INFO, BSL_LOG_LEVEL_DEBUG 161 * @retval #BSL_SUCCESS. 162 * @retval #BSL_LOG_ERR_BAD_PARAM, invalid input parameter. 163 */ 164 int32_t BSL_LOG_SetBinLogLevel(uint32_t level); 165 166 /** 167 * @ingroup bsl_log 168 * @brief Obtain the level of binlogs. 169 * 170 * @retval Level of the binlog. The value can be BSL_LOG_LEVEL_SEC, BSL_LOG_LEVEL_FATAL, BSL_LOG_LEVEL_ERR, 171 * BSL_LOG_LEVEL_WARN, BSL_LOG_LEVEL_INFO, BSL_LOG_LEVEL_DEBUG 172 */ 173 uint32_t BSL_LOG_GetBinLogLevel(void); 174 175 #ifdef __cplusplus 176 } 177 #endif 178 179 #endif // BSL_LOG_H 180