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