1 /**
2  * @file lv_log.h
3  *
4  */
5 
6 #ifndef LV_LOG_H
7 #define LV_LOG_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 #include <stdint.h>
18 
19 /*********************
20  *      DEFINES
21  *********************/
22 
23 /*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/
24 
25 #define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/
26 #define LV_LOG_LEVEL_INFO 1  /**< Log important events*/
27 #define LV_LOG_LEVEL_WARN 2  /**< Log if something unwanted happened but didn't caused problem*/
28 #define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
29 #define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/
30 #define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/
31 #define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels */
32 
33 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE);
34 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO);
35 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN);
36 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR);
37 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_USER);
38 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE);
39 
40 typedef int8_t lv_log_level_t;
41 
42 #if LV_USE_LOG
43 /**********************
44  *      TYPEDEFS
45  **********************/
46 
47 /**
48  * Log print function. Receives "Log Level", "File path", "Line number", "Function name" and "Description".
49  */
50 typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *, const char *);
51 
52 /**********************
53  * GLOBAL PROTOTYPES
54  **********************/
55 
56 /**
57  * Register custom print/write function to call when a log is added.
58  * It can format its "File path", "Line number" and "Description" as required
59  * and send the formatted log message to a console or serial port.
60  * @param print_cb a function pointer to print a log
61  */
62 void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb);
63 
64 /**
65  * Add a log
66  * @param level the level of log. (From `lv_log_level_t` enum)
67  * @param file name of the file when the log added
68  * @param line line number in the source code where the log added
69  * @param func name of the function when the log added
70  * @param format printf-like format string
71  * @param ... parameters for `format`
72  */
73 void _lv_log_add(lv_log_level_t level, const char * file, int line, const char * func, const char * format, ...);
74 
75 /**********************
76  *      MACROS
77  **********************/
78 
79 #if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
80 #define LV_LOG_TRACE(...) _lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, __func__, __VA_ARGS__);
81 #else
82 #define LV_LOG_TRACE(...)
83 #endif
84 
85 #if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
86 #define LV_LOG_INFO(...) _lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__);
87 #else
88 #define LV_LOG_INFO(...)
89 #endif
90 
91 #if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
92 #define LV_LOG_WARN(...) _lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__);
93 #else
94 #define LV_LOG_WARN(...)
95 #endif
96 
97 #if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
98 #define LV_LOG_ERROR(...) _lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__);
99 #else
100 #define LV_LOG_ERROR(...)
101 #endif
102 
103 #if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER
104 #define LV_LOG_USER(...) _lv_log_add(LV_LOG_LEVEL_USER, __FILE__, __LINE__, __func__, __VA_ARGS__);
105 #else
106 #define LV_LOG_USER(...)
107 #endif
108 
109 #else /*LV_USE_LOG*/
110 
111 /*Do nothing if `LV_USE_LOG  0`*/
112 #define _lv_log_add(level, file, line, ...)
113 #define LV_LOG_TRACE(...)
114 #define LV_LOG_INFO(...)
115 #define LV_LOG_WARN(...)
116 #define LV_LOG_ERROR(...)
117 #define LV_LOG_USER(...)
118 #endif /*LV_USE_LOG*/
119 
120 #ifdef __cplusplus
121 } /* extern "C" */
122 #endif
123 
124 #endif /*LV_LOG_H*/
125