mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-21 06:53:01 +08:00
add va_list support to LV_LOG functions
This commit is contained in:
parent
963140fd74
commit
c76ff89af3
@ -9,6 +9,9 @@
|
|||||||
#include "lv_log.h"
|
#include "lv_log.h"
|
||||||
#if LV_USE_LOG
|
#if LV_USE_LOG
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "lv_printf.h"
|
||||||
|
|
||||||
#if LV_LOG_PRINTF
|
#if LV_LOG_PRINTF
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
@ -54,17 +57,23 @@ void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
|
|||||||
* @param level the level of log. (From `lv_log_level_t` enum)
|
* @param level the level of log. (From `lv_log_level_t` enum)
|
||||||
* @param file name of the file when the log added
|
* @param file name of the file when the log added
|
||||||
* @param line line number in the source code where the log added
|
* @param line line number in the source code where the log added
|
||||||
* @param dsc description of the log
|
* @param format printf-like format string
|
||||||
|
* @param ... parameters for `format`
|
||||||
*/
|
*/
|
||||||
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)
|
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * format, ...)
|
||||||
{
|
{
|
||||||
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
|
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
|
||||||
|
|
||||||
if(level >= LV_LOG_LEVEL) {
|
if(level >= LV_LOG_LEVEL) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
char buf[256];
|
||||||
|
lv_vsnprintf(buf, sizeof(buf), format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
#if LV_LOG_PRINTF
|
#if LV_LOG_PRINTF
|
||||||
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
|
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error", "User"};
|
||||||
printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
|
printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], buf, file, line);
|
||||||
#else
|
#else
|
||||||
if(custom_print_cb) custom_print_cb(level, file, line, dsc);
|
if(custom_print_cb) custom_print_cb(level, file, line, dsc);
|
||||||
#endif
|
#endif
|
||||||
|
@ -26,13 +26,15 @@ extern "C" {
|
|||||||
#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/
|
#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/
|
||||||
#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/
|
#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/
|
||||||
#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
|
#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
|
||||||
#define LV_LOG_LEVEL_NONE 4 /**< Do not log anything*/
|
#define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/
|
||||||
#define _LV_LOG_LEVEL_NUM 5 /**< Number of log levels */
|
#define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/
|
||||||
|
#define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels */
|
||||||
|
|
||||||
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE);
|
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE);
|
||||||
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO);
|
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO);
|
||||||
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN);
|
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN);
|
||||||
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR);
|
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR);
|
||||||
|
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_USER);
|
||||||
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE);
|
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE);
|
||||||
|
|
||||||
typedef int8_t lv_log_level_t;
|
typedef int8_t lv_log_level_t;
|
||||||
@ -64,45 +66,55 @@ void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb);
|
|||||||
* @param level the level of log. (From `lv_log_level_t` enum)
|
* @param level the level of log. (From `lv_log_level_t` enum)
|
||||||
* @param file name of the file when the log added
|
* @param file name of the file when the log added
|
||||||
* @param line line number in the source code where the log added
|
* @param line line number in the source code where the log added
|
||||||
* @param dsc description of the log
|
* @param format printf-like format string
|
||||||
|
* @param ... parameters for `format`
|
||||||
*/
|
*/
|
||||||
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc);
|
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * format, ...);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
|
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
|
||||||
#define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc);
|
#define LV_LOG_TRACE(...) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__);
|
||||||
#else
|
#else
|
||||||
#define LV_LOG_TRACE(dsc) \
|
#define LV_LOG_TRACE(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
|
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
|
||||||
#define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc);
|
#define LV_LOG_INFO(...) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__);
|
||||||
#else
|
#else
|
||||||
#define LV_LOG_INFO(dsc) \
|
#define LV_LOG_INFO(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
|
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
|
||||||
#define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc);
|
#define LV_LOG_WARN(...) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, __VA_ARGS__);
|
||||||
#else
|
#else
|
||||||
#define LV_LOG_WARN(dsc) \
|
#define LV_LOG_WARN(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
|
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
|
||||||
#define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc);
|
#define LV_LOG_ERROR(...) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__);
|
||||||
#else
|
#else
|
||||||
#define LV_LOG_ERROR(dsc) \
|
#define LV_LOG_ERROR(...) \
|
||||||
|
{ \
|
||||||
|
; \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER
|
||||||
|
#define LV_LOG_USER(...) lv_log_add(LV_LOG_LEVEL_USER, __FILE__, __LINE__, __VA_ARGS__);
|
||||||
|
#else
|
||||||
|
#define LV_LOG_USER(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
@ -111,23 +123,27 @@ void lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
|||||||
#else /*LV_USE_LOG*/
|
#else /*LV_USE_LOG*/
|
||||||
|
|
||||||
/*Do nothing if `LV_USE_LOG 0`*/
|
/*Do nothing if `LV_USE_LOG 0`*/
|
||||||
#define lv_log_add(level, file, line, dsc) \
|
#define lv_log_add(level, file, line, ...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
#define LV_LOG_TRACE(dsc) \
|
#define LV_LOG_TRACE(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
#define LV_LOG_INFO(dsc) \
|
#define LV_LOG_INFO(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
#define LV_LOG_WARN(dsc) \
|
#define LV_LOG_WARN(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
#define LV_LOG_ERROR(dsc) \
|
#define LV_LOG_ERROR(...) \
|
||||||
|
{ \
|
||||||
|
; \
|
||||||
|
}
|
||||||
|
#define LV_LOG_USER(...) \
|
||||||
{ \
|
{ \
|
||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user