mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
add __func__ to log messages
This commit is contained in:
parent
95c64cf7f3
commit
27e6525a7a
@ -10,6 +10,7 @@
|
||||
#if LV_USE_LOG
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "lv_printf.h"
|
||||
|
||||
#if LV_LOG_PRINTF
|
||||
@ -52,15 +53,17 @@ void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
|
||||
custom_print_cb = print_cb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a log
|
||||
* @param level the level of log. (From `lv_log_level_t` enum)
|
||||
* @param file name of the file when the log added
|
||||
* @param line line number in the source code where the log added
|
||||
* @param func name of the function when the log added
|
||||
* @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 * format, ...)
|
||||
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * func, const char * format, ...)
|
||||
{
|
||||
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
|
||||
|
||||
@ -72,10 +75,19 @@ void lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
||||
va_end(args);
|
||||
|
||||
#if LV_LOG_PRINTF
|
||||
/*Use only the file name not the path*/
|
||||
size_t p;
|
||||
for(p = strlen(file); p > 0; p--) {
|
||||
if(file[p] == '/' || file[p] == '\\') {
|
||||
p++; /*Skip the slash*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error", "User"};
|
||||
printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], buf, file, line);
|
||||
printf("%s: %s \t(%s #%d %s())\n", lvl_prefix[level], buf, &file[p], line ,func);
|
||||
#else
|
||||
if(custom_print_cb) custom_print_cb(level, file, line, buf);
|
||||
if(custom_print_cb) custom_print_cb(level, file, line, func, buf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ typedef int8_t lv_log_level_t;
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Log print function. Receives "Log Level", "File path", "Line number" and "Description".
|
||||
* Log print function. Receives "Log Level", "File path", "Line number", "Function name" and "Description".
|
||||
*/
|
||||
typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *);
|
||||
typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *, const char *);
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
@ -66,17 +66,18 @@ 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 file name of the file when the log added
|
||||
* @param line line number in the source code where the log added
|
||||
* @param func name of the function when the log added
|
||||
* @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 * format, ...);
|
||||
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * func, const char * format, ...);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
|
||||
#define LV_LOG_TRACE(...) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__);
|
||||
#define LV_LOG_TRACE(...) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, __func__, __VA_ARGS__);
|
||||
#else
|
||||
#define LV_LOG_TRACE(...) \
|
||||
{ \
|
||||
@ -85,7 +86,7 @@ void lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
||||
#endif
|
||||
|
||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
|
||||
#define LV_LOG_INFO(...) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__);
|
||||
#define LV_LOG_INFO(...) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__);
|
||||
#else
|
||||
#define LV_LOG_INFO(...) \
|
||||
{ \
|
||||
@ -94,7 +95,7 @@ void lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
||||
#endif
|
||||
|
||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
|
||||
#define LV_LOG_WARN(...) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, __VA_ARGS__);
|
||||
#define LV_LOG_WARN(...) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__);
|
||||
#else
|
||||
#define LV_LOG_WARN(...) \
|
||||
{ \
|
||||
@ -103,7 +104,7 @@ void lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
||||
#endif
|
||||
|
||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
|
||||
#define LV_LOG_ERROR(...) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__);
|
||||
#define LV_LOG_ERROR(...) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__);
|
||||
#else
|
||||
#define LV_LOG_ERROR(...) \
|
||||
{ \
|
||||
@ -112,7 +113,7 @@ void lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
||||
#endif
|
||||
|
||||
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER
|
||||
#define LV_LOG_USER(...) lv_log_add(LV_LOG_LEVEL_USER, __FILE__, __LINE__, __VA_ARGS__);
|
||||
#define LV_LOG_USER(...) lv_log_add(LV_LOG_LEVEL_USER, __FILE__, __LINE__, __func__, __VA_ARGS__);
|
||||
#else
|
||||
#define LV_LOG_USER(...) \
|
||||
{ \
|
||||
|
Loading…
x
Reference in New Issue
Block a user