2018-07-07 08:54:40 +02:00
|
|
|
/**
|
|
|
|
* @file lv_log.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include "lv_log.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_LOG
|
2018-07-07 08:54:40 +02:00
|
|
|
|
|
|
|
#if LV_LOG_PRINTF
|
2018-07-07 12:21:36 +02:00
|
|
|
#include <stdio.h>
|
2018-07-07 08:54:40 +02:00
|
|
|
#endif
|
2019-10-22 13:02:31 -07:00
|
|
|
|
2018-07-07 08:54:40 +02:00
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-05-18 13:48:27 +02:00
|
|
|
static lv_log_print_g_cb_t custom_print_cb;
|
2018-07-07 08:54:40 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* 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
|
2018-07-07 08:54:40 +02:00
|
|
|
*/
|
2019-05-18 13:48:27 +02:00
|
|
|
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
|
2018-07-07 08:54:40 +02:00
|
|
|
{
|
2019-05-18 13:48:27 +02:00
|
|
|
custom_print_cb = print_cb;
|
2018-07-07 08:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
2018-07-07 08:54:40 +02:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
|
2018-07-07 08:54:40 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
if(level >= LV_LOG_LEVEL) {
|
2018-07-07 08:54:40 +02:00
|
|
|
|
|
|
|
#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);
|
2018-07-07 08:54:40 +02:00
|
|
|
#else
|
2019-05-18 13:48:27 +02:00
|
|
|
if(custom_print_cb) custom_print_cb(level, file, line, dsc);
|
2018-07-07 08:54:40 +02:00
|
|
|
#endif
|
2018-10-05 17:22:49 +02:00
|
|
|
}
|
2018-07-07 08:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#endif /*LV_USE_LOG*/
|