1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_misc/lv_log.c

79 lines
1.7 KiB
C
Raw Normal View History

/**
* @file lv_log.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_log.h"
#if LV_USE_LOG
#if LV_LOG_PRINTF
#include <stdio.h>
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
2019-05-18 13:48:27 +02:00
static lv_log_print_g_cb_t custom_print_cb;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
2019-05-18 13:48:27 +02:00
* Register custom print/write function to call when a log is added.
* It can format its "File path", "Line number" and "Description" as required
* and send the formatted log message to a consol or serial port.
* @param print_cb a function pointer to print a log
*/
2019-05-18 13:48:27 +02:00
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
{
2019-05-18 13:48:27 +02:00
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 dsc description of the log
*/
2018-12-22 05:43:49 +07:00
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)
{
2019-04-04 07:15:40 +02:00
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
2018-10-05 17:22:49 +02:00
if(level >= LV_LOG_LEVEL) {
#if LV_LOG_PRINTF
2018-10-05 17:22:49 +02:00
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
2019-04-04 07:15:40 +02:00
printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
#else
2019-05-18 13:48:27 +02:00
if(custom_print_cb) custom_print_cb(level, file, line, dsc);
#endif
2018-10-05 17:22:49 +02:00
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_LOG*/