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.h

145 lines
6.0 KiB
C
Raw Normal View History

/**
* @file lv_log.h
*
*/
#ifndef LV_LOG_H
#define LV_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
2019-03-17 08:33:03 +01:00
#include "../../../lv_conf.h"
#endif
#include <stdint.h>
/*********************
* DEFINES
*********************/
/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/
2018-10-05 15:15:19 +02:00
#define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/
#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/
#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/
#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
#define LV_LOG_LEVEL_NONE 4 /**< Do not log anything*/
#define _LV_LOG_LEVEL_NUM 5 /**< Number of log levels */
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE);
typedef int8_t lv_log_level_t;
#if LV_USE_LOG
2018-10-05 15:15:19 +02:00
/**********************
* TYPEDEFS
**********************/
2019-05-18 13:48:27 +02:00
/**
* Log print function. Receives "Log Level", "File path", "Line number" and "Description".
2019-05-18 13:48:27 +02:00
*/
2019-06-06 06:05:40 +02:00
typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *);
2019-05-18 13:48:27 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
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);
/**
* 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);
/**********************
* MACROS
**********************/
2019-06-25 18:27:10 +02:00
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
2019-06-27 07:16:15 +02:00
#define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc);
2019-06-25 18:27:10 +02:00
#else
2019-06-27 07:16:15 +02:00
#define LV_LOG_TRACE(dsc) \
{ \
; \
}
2019-06-25 18:27:10 +02:00
#endif
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
2019-06-27 07:16:15 +02:00
#define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc);
2019-06-25 18:27:10 +02:00
#else
2019-06-27 07:16:15 +02:00
#define LV_LOG_INFO(dsc) \
{ \
; \
}
2019-06-25 18:27:10 +02:00
#endif
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
2019-06-27 07:16:15 +02:00
#define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc);
2019-06-25 18:27:10 +02:00
#else
2019-06-27 07:16:15 +02:00
#define LV_LOG_WARN(dsc) \
{ \
; \
}
2019-06-25 18:27:10 +02:00
#endif
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
2019-06-27 07:16:15 +02:00
#define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc);
2019-06-25 18:27:10 +02:00
#else
2019-06-27 07:16:15 +02:00
#define LV_LOG_ERROR(dsc) \
{ \
; \
}
2019-06-25 18:27:10 +02:00
#endif
#else /*LV_USE_LOG*/
/*Do nothing if `LV_USE_LOG 0`*/
2019-06-06 06:05:40 +02:00
#define lv_log_add(level, file, line, dsc) \
{ \
; \
2019-04-04 07:15:40 +02:00
}
2019-06-06 06:05:40 +02:00
#define LV_LOG_TRACE(dsc) \
{ \
; \
2019-04-04 07:15:40 +02:00
}
2019-06-06 06:05:40 +02:00
#define LV_LOG_INFO(dsc) \
{ \
; \
2019-04-04 07:15:40 +02:00
}
2019-06-06 06:05:40 +02:00
#define LV_LOG_WARN(dsc) \
{ \
; \
2019-04-04 07:15:40 +02:00
}
2019-06-06 06:05:40 +02:00
#define LV_LOG_ERROR(dsc) \
{ \
; \
2019-04-04 07:15:40 +02:00
}
#endif /*LV_USE_LOG*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_LOG_H*/