feat(log): add LV_LOG_PRINT_CB to set a default log print cb (#6095)

Co-authored-by: Neo Xu <xuxingliang@xiaomi.com>
This commit is contained in:
Gabor Kiss-Vamosi
2024-04-25 17:17:38 +02:00
committed by GitHub
parent 79b64c8bd8
commit addc3f0c73
4 changed files with 28 additions and 12 deletions
+6
View File
@@ -240,6 +240,11 @@
*0: User need to register a callback with `lv_log_register_print_cb()`*/ *0: User need to register a callback with `lv_log_register_print_cb()`*/
#define LV_LOG_PRINTF 0 #define LV_LOG_PRINTF 0
/*Set callback to print the logs.
*E.g `my_print`. The prototype should be `void my_print(lv_log_level_t level, const char * buf)`
*Can be overwritten by `lv_log_register_print_cb`*/
//#define LV_LOG_PRINT_CB
/*1: Enable print timestamp; /*1: Enable print timestamp;
*0: Disable print timestamp*/ *0: Disable print timestamp*/
#define LV_LOG_USE_TIMESTAMP 1 #define LV_LOG_USE_TIMESTAMP 1
@@ -248,6 +253,7 @@
*0: Do not print file and line number of the log*/ *0: Do not print file and line number of the log*/
#define LV_LOG_USE_FILE_LINE 1 #define LV_LOG_USE_FILE_LINE 1
/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/ /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
#define LV_LOG_TRACE_MEM 1 #define LV_LOG_TRACE_MEM 1
#define LV_LOG_TRACE_TIMER 1 #define LV_LOG_TRACE_TIMER 1
+6
View File
@@ -616,6 +616,11 @@
#endif #endif
#endif #endif
/*Set callback to print the logs.
*E.g `my_print`. The prototype should be `void my_print(lv_log_level_t level, const char * buf)`
*Can be overwritten by `lv_log_register_print_cb`*/
//#define LV_LOG_PRINT_CB
/*1: Enable print timestamp; /*1: Enable print timestamp;
*0: Disable print timestamp*/ *0: Disable print timestamp*/
#ifndef LV_LOG_USE_TIMESTAMP #ifndef LV_LOG_USE_TIMESTAMP
@@ -644,6 +649,7 @@
#endif #endif
#endif #endif
/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/ /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
#ifndef LV_LOG_TRACE_MEM #ifndef LV_LOG_TRACE_MEM
#ifdef _LV_KCONFIG_PRESENT #ifdef _LV_KCONFIG_PRESENT
+5
View File
@@ -96,6 +96,11 @@ static inline void lv_global_init(lv_global_t * global)
global->event_last_register_id = _LV_EVENT_LAST; global->event_last_register_id = _LV_EVENT_LAST;
lv_rand_set_seed(0x1234ABCD); lv_rand_set_seed(0x1234ABCD);
#ifdef LV_LOG_PRINT_CB
void LV_LOG_PRINT_CB(lv_log_level_t, const char * txt);
global->custom_log_print_cb = LV_LOG_PRINT_CB;
#endif
#if defined(LV_DRAW_SW_SHADOW_CACHE_SIZE) && LV_DRAW_SW_SHADOW_CACHE_SIZE > 0 #if defined(LV_DRAW_SW_SHADOW_CACHE_SIZE) && LV_DRAW_SW_SHADOW_CACHE_SIZE > 0
global->sw_shadow_cache.cache_size = -1; global->sw_shadow_cache.cache_size = -1;
global->sw_shadow_cache.cache_r = -1; global->sw_shadow_cache.cache_r = -1;
+1 -2
View File
@@ -102,7 +102,7 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
vprintf(format, args); vprintf(format, args);
printf(LOG_FILE_LINE_FMT "\n" LOG_FILE_LINE_EXPR); printf(LOG_FILE_LINE_FMT "\n" LOG_FILE_LINE_EXPR);
fflush(stdout); fflush(stdout);
#else #endif
if(custom_print_cb) { if(custom_print_cb) {
char buf[512]; char buf[512];
char msg[256]; char msg[256];
@@ -111,7 +111,6 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
lvl_prefix[level], LOG_TIMESTAMP_EXPR func, msg LOG_FILE_LINE_EXPR); lvl_prefix[level], LOG_TIMESTAMP_EXPR func, msg LOG_FILE_LINE_EXPR);
custom_print_cb(level, buf); custom_print_cb(level, buf);
} }
#endif
#if LV_LOG_USE_TIMESTAMP #if LV_LOG_USE_TIMESTAMP
last_log_time = t; last_log_time = t;