aboutsummaryrefslogtreecommitdiff
path: root/src/misc/lv_log.h
blob: a04898343cab8f2486d04c37e2cc21f4f9eebf36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * @file lv_log.h
 *
 */

#ifndef LV_LOG_H
#define LV_LOG_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/
#include "../lv_conf_internal.h"

#include "lv_types.h"

/*********************
 *      DEFINES
 *********************/

/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/

#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_USER  4 /**< Custom logs from the user*/
#define LV_LOG_LEVEL_NONE  5 /**< Do not log anything*/
#define LV_LOG_LEVEL_NUM  6 /**< 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_USER);
LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE);

typedef int8_t lv_log_level_t;

#if LV_USE_LOG

#if LV_LOG_USE_FILE_LINE
#define LV_LOG_FILE __FILE__
#define LV_LOG_LINE __LINE__
#else
#define LV_LOG_FILE NULL
#define LV_LOG_LINE 0
#endif

/**********************
 *      TYPEDEFS
 **********************/

/**
 * Log print function. Receives a string buffer to print".
 */
typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char * buf);

/**********************
 * GLOBAL PROTOTYPES
 **********************/

/**
 * 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 console or serial port.
 * @param           print_cb a function pointer to print a log
 */
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb);

/**
 * Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h`
 * and/or a print callback if registered with `lv_log_register_print_cb`
 * @param format    printf-like format string
 * @param ...       parameters for `format`
 */
void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2);

/**
 * 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 func      name of the function when the log added
 * @param format    printf-like format string
 * @param ...       parameters for `format`
 */
void lv_log_add(lv_log_level_t level, const char * file, int line,
                const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6);

/**********************
 *      MACROS
 **********************/
#ifndef LV_LOG_TRACE
#  if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE
#    define LV_LOG_TRACE(...) lv_log_add(LV_LOG_LEVEL_TRACE, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
#  else
#    define LV_LOG_TRACE(...) do {}while(0)
#  endif
#endif

#ifndef LV_LOG_INFO
#  if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
#    define LV_LOG_INFO(...) lv_log_add(LV_LOG_LEVEL_INFO, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
#  else
#    define LV_LOG_INFO(...) do {}while(0)
#  endif
#endif

#ifndef LV_LOG_WARN
#  if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN
#    define LV_LOG_WARN(...) lv_log_add(LV_LOG_LEVEL_WARN, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
#  else
#    define LV_LOG_WARN(...) do {}while(0)
#  endif
#endif

#ifndef LV_LOG_ERROR
#  if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR
#    define LV_LOG_ERROR(...) lv_log_add(LV_LOG_LEVEL_ERROR, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
#  else
#    define LV_LOG_ERROR(...) do {}while(0)
#  endif
#endif

#ifndef LV_LOG_USER
#  if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER
#    define LV_LOG_USER(...) lv_log_add(LV_LOG_LEVEL_USER, LV_LOG_FILE, LV_LOG_LINE, __func__, __VA_ARGS__)
#  else
#    define LV_LOG_USER(...) do {}while(0)
#  endif
#endif

#ifndef LV_LOG
#  if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE
#    define LV_LOG(...) lv_log(__VA_ARGS__)
#  else
#    define LV_LOG(...) do {} while(0)
#  endif
#endif

#else /*LV_USE_LOG*/

/*Do nothing if `LV_USE_LOG 0`*/
#define lv_log_add(level, file, line, ...)
#define LV_LOG_TRACE(...) do {}while(0)
#define LV_LOG_INFO(...) do {}while(0)
#define LV_LOG_WARN(...) do {}while(0)
#define LV_LOG_ERROR(...) do {}while(0)
#define LV_LOG_USER(...) do {}while(0)
#define LV_LOG(...) do {}while(0)

#endif /*LV_USE_LOG*/

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*LV_LOG_H*/