mirror of
https://github.com/lvgl/lvgl.git
synced 2026-06-02 17:47:28 +08:00
feat(log): improve lv_log and add log the result from lv_demo_benchmark (#3084)
* feat(log): improve log * Update log.md * Update log.md * fix: fix formatting issue * fix: fix formatting again... * fix: remove blanks
This commit is contained in:
@@ -780,6 +780,12 @@ static void scene_next_task_cb(lv_timer_t * timer)
|
|||||||
lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
|
lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
|
||||||
lv_table_set_cell_value(table, row, 0, "Slow but common cases");
|
lv_table_set_cell_value(table, row, 0, "Slow but common cases");
|
||||||
// lv_table_set_cell_type(table, row, 0, 4);
|
// lv_table_set_cell_type(table, row, 0, 4);
|
||||||
|
|
||||||
|
LV_LOG("\r\n"
|
||||||
|
"LVGL v%d.%d.%d " LVGL_VERSION_INFO
|
||||||
|
" Benchmark (in csv format)\r\n",
|
||||||
|
LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
for(i = 0; i < sizeof(scenes) / sizeof(scene_dsc_t) - 1; i++) {
|
for(i = 0; i < sizeof(scenes) / sizeof(scene_dsc_t) - 1; i++) {
|
||||||
@@ -793,6 +799,8 @@ static void scene_next_task_cb(lv_timer_t * timer)
|
|||||||
// lv_table_set_cell_type(table, row, 0, 2);
|
// lv_table_set_cell_type(table, row, 0, 2);
|
||||||
// lv_table_set_cell_type(table, row, 1, 2);
|
// lv_table_set_cell_type(table, row, 1, 2);
|
||||||
|
|
||||||
|
LV_LOG("%s,%s\r\n", scenes[i].name, buf);
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,11 +808,14 @@ static void scene_next_task_cb(lv_timer_t * timer)
|
|||||||
lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
|
lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
|
||||||
lv_table_set_cell_value(table, row, 0, buf);
|
lv_table_set_cell_value(table, row, 0, buf);
|
||||||
|
|
||||||
|
LV_LOG("%s,", buf);
|
||||||
|
|
||||||
lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
|
lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
|
||||||
lv_table_set_cell_value(table, row, 1, buf);
|
lv_table_set_cell_value(table, row, 1, buf);
|
||||||
|
|
||||||
// lv_table_set_cell_type(table, row, 0, 2);
|
// lv_table_set_cell_type(table, row, 0, 2);
|
||||||
// lv_table_set_cell_type(table, row, 1, 2);
|
// lv_table_set_cell_type(table, row, 1, 2);
|
||||||
|
LV_LOG("%s\r\n", buf);
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
@@ -837,11 +848,15 @@ static void scene_next_task_cb(lv_timer_t * timer)
|
|||||||
// lv_table_set_cell_type(table, row, 1, 2);
|
// lv_table_set_cell_type(table, row, 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LV_LOG("%s,%s\r\n", scenes[i].name, buf);
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
|
|
||||||
lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
|
lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
|
||||||
lv_table_set_cell_value(table, row, 0, buf);
|
lv_table_set_cell_value(table, row, 0, buf);
|
||||||
|
|
||||||
|
LV_LOG("%s,", buf);
|
||||||
|
|
||||||
lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
|
lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
|
||||||
lv_table_set_cell_value(table, row, 1, buf);
|
lv_table_set_cell_value(table, row, 1, buf);
|
||||||
|
|
||||||
@@ -855,6 +870,8 @@ static void scene_next_task_cb(lv_timer_t * timer)
|
|||||||
// lv_table_set_cell_type(table, row, 1, 2);
|
// lv_table_set_cell_type(table, row, 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LV_LOG("%s\r\n", buf);
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -43,4 +43,11 @@ lv_log_register_print_cb(my_log_cb);
|
|||||||
|
|
||||||
## Add logs
|
## Add logs
|
||||||
|
|
||||||
You can also use the log module via the `LV_LOG_TRACE/INFO/WARN/ERROR/USER(text)` functions.
|
You can also use the log module via the `LV_LOG_TRACE/INFO/WARN/ERROR/USER(text)` or `LV_LOG(text)` functions. Here:
|
||||||
|
|
||||||
|
- `LV_LOG_TRACE/INFO/WARN/ERROR/USER(text)` append following information to your `text`
|
||||||
|
- Log Level
|
||||||
|
- \_\_FILE\_\_
|
||||||
|
- \_\_LINE\_\_
|
||||||
|
- \_\_func\_\_
|
||||||
|
- `LV_LOG(text)` is similar to `LV_LOG_USER` but has no extra information attached.
|
||||||
|
|||||||
+20
-3
@@ -112,12 +112,29 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_log(const char * buf)
|
void lv_log(const char * format, ...)
|
||||||
{
|
{
|
||||||
|
if(LV_LOG_LEVEL >= LV_LOG_LEVEL_NONE) return; /* disable log */
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
|
||||||
#if LV_LOG_PRINTF
|
#if LV_LOG_PRINTF
|
||||||
puts(buf);
|
vprintf(format, args);
|
||||||
|
#else
|
||||||
|
if(custom_print_cb) {
|
||||||
|
char buf[512];
|
||||||
|
#if LV_SPRINTF_CUSTOM
|
||||||
|
lv_vsnprintf(buf, sizeof(buf), format, args);
|
||||||
|
#else
|
||||||
|
lv_vaformat_t vaf = {format, &args};
|
||||||
|
lv_snprintf(buf, sizeof(buf), "%pV", (void *)&vaf);
|
||||||
#endif
|
#endif
|
||||||
if(custom_print_cb) custom_print_cb(buf);
|
custom_print_cb(buf);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
|||||||
+25
-2
@@ -66,9 +66,22 @@ void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb);
|
|||||||
/**
|
/**
|
||||||
* Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h`
|
* Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h`
|
||||||
* and/or a print callback if registered with `lv_log_register_print_cb`
|
* and/or a print callback if registered with `lv_log_register_print_cb`
|
||||||
* @param buf a string message to print
|
* @param format printf-like format string
|
||||||
|
* @param ... parameters for `format`
|
||||||
*/
|
*/
|
||||||
void lv_log(const char * buf);
|
void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a log
|
* Add a log
|
||||||
@@ -125,6 +138,14 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line,
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LV_LOG
|
||||||
|
# if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE
|
||||||
|
# define LV_LOG(...) lv_log(__VA_ARGS__)
|
||||||
|
# else
|
||||||
|
# define LV_LOG(...) do {} while(0)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#else /*LV_USE_LOG*/
|
#else /*LV_USE_LOG*/
|
||||||
|
|
||||||
/*Do nothing if `LV_USE_LOG 0`*/
|
/*Do nothing if `LV_USE_LOG 0`*/
|
||||||
@@ -134,6 +155,8 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line,
|
|||||||
#define LV_LOG_WARN(...) do {}while(0)
|
#define LV_LOG_WARN(...) do {}while(0)
|
||||||
#define LV_LOG_ERROR(...) do {}while(0)
|
#define LV_LOG_ERROR(...) do {}while(0)
|
||||||
#define LV_LOG_USER(...) do {}while(0)
|
#define LV_LOG_USER(...) do {}while(0)
|
||||||
|
#define LV_LOG(...) do {}while(0)
|
||||||
|
|
||||||
#endif /*LV_USE_LOG*/
|
#endif /*LV_USE_LOG*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Reference in New Issue
Block a user