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