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 18 #include "lv_types.h" 19 20 /********************* 21 * DEFINES 22 *********************/ 23 24 /*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/ 25 26 #define LV_LOG_LEVEL_TRACE 0 /**< Log detailed information. */ 27 #define LV_LOG_LEVEL_INFO 1 /**< Log important events. */ 28 #define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem. */ 29 #define LV_LOG_LEVEL_ERROR 3 /**< Log only critical issues, when system may fail. */ 30 #define LV_LOG_LEVEL_USER 4 /**< Log only custom log messages added by the user. */ 31 #define LV_LOG_LEVEL_NONE 5 /**< Do not log anything. */ 32 #define LV_LOG_LEVEL_NUM 6 /**< Number of log levels */ 33 34 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE); 35 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO); 36 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN); 37 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR); 38 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_USER); 39 LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE); 40 41 typedef int8_t lv_log_level_t; 42 43 #if LV_USE_LOG 44 45 #if LV_LOG_USE_FILE_LINE 46 #define LV_LOG_FILE __FILE__ 47 #define LV_LOG_LINE __LINE__ 48 #else 49 #define LV_LOG_FILE NULL 50 #define LV_LOG_LINE 0 51 #endif 52 53 /********************** 54 * TYPEDEFS 55 **********************/ 56 57 /** 58 * Log print function. Receives a string buffer to print". 59 */ 60 typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char * buf); 61 62 /********************** 63 * GLOBAL PROTOTYPES 64 **********************/ 65 66 /** 67 * Register custom print/write function to call when a log is added. 68 * It can format its "File path", "Line number" and "Description" as required 69 * and send the formatted log message to a console or serial port. 70 * @param print_cb a function pointer to print a log 71 */ 72 void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb); 73 74 /** 75 * Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h` 76 * and/or a print callback if registered with `lv_log_register_print_cb` 77 * @param format printf-like format string 78 * @param ... parameters for `format` 79 */ 80 void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2); 81 82 /** 83 * Add a log 84 * @param level the level of log. (From `lv_log_level_t` enum) 85 * @param file name of the file when the log added 86 * @param line line number in the source code where the log added 87 * @param func name of the function when the log added 88 * @param format printf-like format string 89 * @param ... parameters for `format` 90 */ 91 void lv_log_add(lv_log_level_t level, const char * file, int line, 92 const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6); 93 94 /********************** 95 * MACROS 96 **********************/ 97 #ifndef LV_LOG_TRACE 98 # if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE 99 # define LV_LOG_TRACE(...) lv_log_add(LV_LOG_LEVEL_TRACE, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__) 100 # else 101 # define LV_LOG_TRACE(...) do {}while(0) 102 # endif 103 #endif 104 105 #ifndef LV_LOG_INFO 106 # if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO 107 # define LV_LOG_INFO(...) lv_log_add(LV_LOG_LEVEL_INFO, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__) 108 # else 109 # define LV_LOG_INFO(...) do {}while(0) 110 # endif 111 #endif 112 113 #ifndef LV_LOG_WARN 114 # if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN 115 # define LV_LOG_WARN(...) lv_log_add(LV_LOG_LEVEL_WARN, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__) 116 # else 117 # define LV_LOG_WARN(...) do {}while(0) 118 # endif 119 #endif 120 121 #ifndef LV_LOG_ERROR 122 # if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR 123 # define LV_LOG_ERROR(...) lv_log_add(LV_LOG_LEVEL_ERROR, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__) 124 # else 125 # define LV_LOG_ERROR(...) do {}while(0) 126 # endif 127 #endif 128 129 #ifndef LV_LOG_USER 130 # if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER 131 # define LV_LOG_USER(...) lv_log_add(LV_LOG_LEVEL_USER, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__) 132 # else 133 # define LV_LOG_USER(...) do {}while(0) 134 # endif 135 #endif 136 137 #ifndef LV_LOG 138 # if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE 139 # define LV_LOG(...) lv_log(__VA_ARGS__) 140 # else 141 # define LV_LOG(...) do {} while(0) 142 # endif 143 #endif 144 145 #else /*LV_USE_LOG*/ 146 147 /*Do nothing if `LV_USE_LOG 0`*/ 148 #define lv_log_add(level, file, line, ...) 149 #define LV_LOG_TRACE(...) do {}while(0) 150 #define LV_LOG_INFO(...) do {}while(0) 151 #define LV_LOG_WARN(...) do {}while(0) 152 #define LV_LOG_ERROR(...) do {}while(0) 153 #define LV_LOG_USER(...) do {}while(0) 154 #define LV_LOG(...) do {}while(0) 155 156 #endif /*LV_USE_LOG*/ 157 158 #ifdef __cplusplus 159 } /*extern "C"*/ 160 #endif 161 162 #endif /*LV_LOG_H*/ 163