diff --git a/demos/benchmark/lv_demo_benchmark.c b/demos/benchmark/lv_demo_benchmark.c index a277ec4ee..abb5ee639 100644 --- a/demos/benchmark/lv_demo_benchmark.c +++ b/demos/benchmark/lv_demo_benchmark.c @@ -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_set_cell_value(table, row, 0, "Slow but common cases"); // 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++; char buf[256]; for(i = 0; i < sizeof(scenes) / sizeof(scene_dsc_t) - 1; i++) { @@ -793,19 +799,24 @@ 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, 1, 2); + LV_LOG("%s,%s\r\n", scenes[i].name, buf); + row++; } if(scenes[i].fps_opa < 20 && LV_MAX(scenes[i].weight / 2, 1) >= 10) { lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name); 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_table_set_cell_value(table, row, 1, buf); // lv_table_set_cell_type(table, row, 0, 2); // lv_table_set_cell_type(table, row, 1, 2); - + LV_LOG("%s\r\n", buf); + row++; } } @@ -836,12 +847,16 @@ 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, 1, 2); } + + LV_LOG("%s,%s\r\n", scenes[i].name, buf); row++; lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name); 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_table_set_cell_value(table, row, 1, buf); @@ -854,6 +869,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, 1, 2); } + + LV_LOG("%s\r\n", buf); row++; } diff --git a/docs/porting/log.md b/docs/porting/log.md index fac928d21..d3c9071b8 100644 --- a/docs/porting/log.md +++ b/docs/porting/log.md @@ -43,4 +43,11 @@ lv_log_register_print_cb(my_log_cb); ## 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. diff --git a/src/misc/lv_log.c b/src/misc/lv_log.c index 63441d6a4..d79463f2b 100644 --- a/src/misc/lv_log.c +++ b/src/misc/lv_log.c @@ -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 - 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 - if(custom_print_cb) custom_print_cb(buf); + custom_print_cb(buf); + } +#endif + + va_end(args); } /********************** diff --git a/src/misc/lv_log.h b/src/misc/lv_log.h index fa6f5ac6b..5bda4562e 100644 --- a/src/misc/lv_log.h +++ b/src/misc/lv_log.h @@ -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` * 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 @@ -125,6 +138,14 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, # 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*/ /*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_ERROR(...) do {}while(0) #define LV_LOG_USER(...) do {}while(0) +#define LV_LOG(...) do {}while(0) + #endif /*LV_USE_LOG*/ #ifdef __cplusplus