• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef __LOGGER_H__
17 #define __LOGGER_H__
18 
19 #include <stdio.h>
20 #include <stdint.h>
21 #include "securec.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define LOG_MAX_SIZE 1024
28 
29 typedef enum {
30     ENUM_LOG_LEVEL_TRACE,      /* Basic level */
31     ENUM_LOG_LEVEL_DEBUG,      /* Debugging level */
32     ENUM_LOG_LEVEL_WARNING,    /* Warning level */
33     ENUM_LOG_LEVEL_ERROR,      /* Error level */
34     ENUM_LOG_LEVEL_FATAL       /* Fatal level */
35 } LogLevel;
36 
37 /**
38 * @ingroup log
39 * @brief Record error information based on the log level
40 *
41 * @par
42 * Record error information based on the log level
43 *
44 * @attention
45 *
46 * @param[in] level Log level
47 * @param[in] file File where the error information is stored
48 * @param[in] line Number of the line where the error information is stored
49 * @param[in] fmt Format character string for printing
50 *
51 * @retval 0 Success
52 * @retval others failure
53 */
54 int LogWrite(LogLevel level, const char *file, int line, const char *fmt, ...);
55 
56 #define LOG_DEBUG(...) LogWrite(ENUM_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
57 #define LOG_ERROR(...) LogWrite(ENUM_LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
58 
59 #ifdef __cplusplus
60 }
61 #endif // __cplusplus
62 
63 #endif // __LOGGER_H__
64