-
Notifications
You must be signed in to change notification settings - Fork 7
/
logger.h
85 lines (73 loc) · 2.69 KB
/
logger.h
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
#ifndef __LOGGER_H__
#define __LOGGER_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include "globalDefines.h"
typedef struct Logger_Event {
va_list ap;
const char *fmt;
const char *file;
const char *function;
void *udata;
int line;
uint8_t level;
bool newLine;
} Logger_Event;
void Logger_init(void);
#if DEBUG_LOG_LEVEL_TRACE >= DEBUG_LOG_LEVEL && !defined(NO_DEBUG_LOG)
#define Logger_trace(...) Logger_log_marco(DEBUG_LOG_LEVEL_TRACE, true, __VA_ARGS__)
#define Logger_trace_nonl(...) Logger_log_marco(DEBUG_LOG_LEVEL_TRACE, false, __VA_ARGS__)
#else
#define Logger_trace(...)
#define Logger_trace_nonl(...)
#endif
#if DEBUG_LOG_LEVEL_DEBUG >= DEBUG_LOG_LEVEL && !defined(NO_DEBUG_LOG)
#define Logger_debug(...) Logger_log_marco(DEBUG_LOG_LEVEL_DEBUG, true, __VA_ARGS__)
#define Logger_debug_nonl(...) Logger_log_marco(DEBUG_LOG_LEVEL_DEBUG, false, __VA_ARGS__)
#else
#define Logger_debug(...)
#define Logger_debug_nonl(...)
#endif
#if DEBUG_LOG_LEVEL_INFO >= DEBUG_LOG_LEVEL && !defined(NO_DEBUG_LOG)
#define Logger_info(...) Logger_log_marco(DEBUG_LOG_LEVEL_INFO, true, __VA_ARGS__)
#define Logger_info_nonl(...) Logger_log_marco(DEBUG_LOG_LEVEL_INFO, false, __VA_ARGS__)
#else
#define Logger_info(...)
#define Logger_info_nonl(...)
#endif
#if DEBUG_LOG_LEVEL_WARN >= DEBUG_LOG_LEVEL && !defined(NO_DEBUG_LOG)
#define Logger_warn(...) Logger_log_marco(DEBUG_LOG_LEVEL_WARN, true, __VA_ARGS__)
#define Logger_warn_nonl(...) Logger_log_marco(DEBUG_LOG_LEVEL_WARN, false, __VA_ARGS__)
#else
#define Logger_warn(...)
#define Logger_warn_nonl(...)
#endif
#if DEBUG_LOG_LEVEL_ERROR >= DEBUG_LOG_LEVEL && !defined(NO_DEBUG_LOG)
#define Logger_error(...) Logger_log_marco(DEBUG_LOG_LEVEL_ERROR, true, __VA_ARGS__)
#define Logger_error_nonl(...) Logger_log_marco(DEBUG_LOG_LEVEL_ERROR, false, __VA_ARGS__)
#else
#define Logger_error(...)
#define Logger_error_nonl(...)
#endif
#if DEBUG_LOG_LEVEL_FATAL >= DEBUG_LOG_LEVEL && !defined(NO_DEBUG_LOG)
#define Logger_fatal(...) Logger_log_marco(DEBUG_LOG_LEVEL_FATAL, true, __VA_ARGS__)
#define Logger_fatal_nonl(...) Logger_log_marco(DEBUG_LOG_LEVEL_FATAL, false, __VA_ARGS__)
#else
#define Logger_fatal(...)
#define Logger_fatal_nonl(...)
#endif
#define Logger_log_marco(level, newline, ...) Logger_log(level, newline, __FILE__, __func__, __LINE__, __VA_ARGS__)
void Logger_log(uint8_t level, bool newLine, const char *file, const char *function, int line, const char *fmt, ...);
void Logger_setLevel(uint8_t level);
void Logger_setColored(bool colored);
bool Logger_needed(uint8_t level);
void Logger_newLine(void);
#ifdef __cplusplus
}
#endif
#endif