Skip to content

Commit ba38a4b

Browse files
feat(log): improve lv_log and add log the result from lv_demo_benchmark (lvgl#3084)
* feat(log): improve log * Update log.md * Update log.md * fix: fix formatting issue * fix: fix formatting again... * fix: remove blanks
1 parent 48d87e1 commit ba38a4b

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

demos/benchmark/lv_demo_benchmark.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,12 @@ static void scene_next_task_cb(lv_timer_t * timer)
780780
lv_table_add_cell_ctrl(table, row, 0, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
781781
lv_table_set_cell_value(table, row, 0, "Slow but common cases");
782782
// lv_table_set_cell_type(table, row, 0, 4);
783+
784+
LV_LOG("\r\n"
785+
"LVGL v%d.%d.%d " LVGL_VERSION_INFO
786+
" Benchmark (in csv format)\r\n",
787+
LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);
788+
783789
row++;
784790
char buf[256];
785791
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)
793799
// lv_table_set_cell_type(table, row, 0, 2);
794800
// lv_table_set_cell_type(table, row, 1, 2);
795801

802+
LV_LOG("%s,%s\r\n", scenes[i].name, buf);
803+
796804
row++;
797805
}
798806

799807
if(scenes[i].fps_opa < 20 && LV_MAX(scenes[i].weight / 2, 1) >= 10) {
800808
lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
801809
lv_table_set_cell_value(table, row, 0, buf);
810+
811+
LV_LOG("%s,", buf);
802812

803813
lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
804814
lv_table_set_cell_value(table, row, 1, buf);
805815

806816
// lv_table_set_cell_type(table, row, 0, 2);
807817
// lv_table_set_cell_type(table, row, 1, 2);
808-
818+
LV_LOG("%s\r\n", buf);
819+
809820
row++;
810821
}
811822
}
@@ -836,12 +847,16 @@ static void scene_next_task_cb(lv_timer_t * timer)
836847
// lv_table_set_cell_type(table, row, 0, 2);
837848
// lv_table_set_cell_type(table, row, 1, 2);
838849
}
850+
851+
LV_LOG("%s,%s\r\n", scenes[i].name, buf);
839852

840853
row++;
841854

842855
lv_snprintf(buf, sizeof(buf), "%s + opa", scenes[i].name);
843856
lv_table_set_cell_value(table, row, 0, buf);
844857

858+
LV_LOG("%s,", buf);
859+
845860
lv_snprintf(buf, sizeof(buf), "%"LV_PRIu32, scenes[i].fps_opa);
846861
lv_table_set_cell_value(table, row, 1, buf);
847862

@@ -854,6 +869,8 @@ static void scene_next_task_cb(lv_timer_t * timer)
854869
// lv_table_set_cell_type(table, row, 0, 2);
855870
// lv_table_set_cell_type(table, row, 1, 2);
856871
}
872+
873+
LV_LOG("%s\r\n", buf);
857874

858875
row++;
859876
}

docs/porting/log.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ lv_log_register_print_cb(my_log_cb);
4343
4444
## Add logs
4545
46-
You can also use the log module via the `LV_LOG_TRACE/INFO/WARN/ERROR/USER(text)` functions.
46+
You can also use the log module via the `LV_LOG_TRACE/INFO/WARN/ERROR/USER(text)` or `LV_LOG(text)` functions. Here:
47+
48+
- `LV_LOG_TRACE/INFO/WARN/ERROR/USER(text)` append following information to your `text`
49+
- Log Level
50+
- \_\_FILE\_\_
51+
- \_\_LINE\_\_
52+
- \_\_func\_\_
53+
- `LV_LOG(text)` is similar to `LV_LOG_USER` but has no extra information attached.

src/misc/lv_log.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,29 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
112112
}
113113
}
114114

115-
void lv_log(const char * buf)
115+
void lv_log(const char * format, ...)
116116
{
117+
if(LV_LOG_LEVEL >= LV_LOG_LEVEL_NONE) return; /* disable log */
118+
119+
va_list args;
120+
va_start(args, format);
121+
117122
#if LV_LOG_PRINTF
118-
puts(buf);
123+
vprintf(format, args);
124+
#else
125+
if(custom_print_cb) {
126+
char buf[512];
127+
#if LV_SPRINTF_CUSTOM
128+
lv_vsnprintf(buf, sizeof(buf), format, args);
129+
#else
130+
lv_vaformat_t vaf = {format, &args};
131+
lv_snprintf(buf, sizeof(buf), "%pV", (void *)&vaf);
132+
#endif
133+
custom_print_cb(buf);
134+
}
119135
#endif
120-
if(custom_print_cb) custom_print_cb(buf);
136+
137+
va_end(args);
121138
}
122139

123140
/**********************

src/misc/lv_log.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,22 @@ void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb);
6666
/**
6767
* Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h`
6868
* and/or a print callback if registered with `lv_log_register_print_cb`
69-
* @param buf a string message to print
69+
* @param format printf-like format string
70+
* @param ... parameters for `format`
7071
*/
71-
void lv_log(const char * buf);
72+
void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2);
73+
74+
/**
75+
* Add a log
76+
* @param level the level of log. (From `lv_log_level_t` enum)
77+
* @param file name of the file when the log added
78+
* @param line line number in the source code where the log added
79+
* @param func name of the function when the log added
80+
* @param format printf-like format string
81+
* @param ... parameters for `format`
82+
*/
83+
void _lv_log_add(lv_log_level_t level, const char * file, int line,
84+
const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6);
7285

7386
/**
7487
* Add a log
@@ -125,6 +138,14 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line,
125138
# endif
126139
#endif
127140

141+
#ifndef LV_LOG
142+
# if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE
143+
# define LV_LOG(...) lv_log(__VA_ARGS__)
144+
# else
145+
# define LV_LOG(...) do {} while(0)
146+
# endif
147+
#endif
148+
128149
#else /*LV_USE_LOG*/
129150

130151
/*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,
134155
#define LV_LOG_WARN(...) do {}while(0)
135156
#define LV_LOG_ERROR(...) do {}while(0)
136157
#define LV_LOG_USER(...) do {}while(0)
158+
#define LV_LOG(...) do {}while(0)
159+
137160
#endif /*LV_USE_LOG*/
138161

139162
#ifdef __cplusplus

0 commit comments

Comments
 (0)