reactor-uc 0.1
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1#ifndef REACTOR_UC_LOGGING_H
2#define REACTOR_UC_LOGGING_H
3#include <sys/types.h>
4#include <inttypes.h>
5
6// The different verbosity levels supported
7#define LF_LOG_LEVEL_OFF 0
8#define LF_LOG_LEVEL_ERROR 1
9#define LF_LOG_LEVEL_WARN 2
10#define LF_LOG_LEVEL_INFO 3
11#define LF_LOG_LEVEL_LOG 4
12#define LF_LOG_LEVEL_DEBUG 5
13
14// Add color codes to the output
15#ifndef LF_COLORIZE_LOGS
16#define LF_COLORIZE_LOGS 1
17#endif
18
19// Add timestamp to the logs
20#if !defined(LF_TIMESTAMP_LOGS) && !defined(PLATFORM_FLEXPRET)
21#define LF_TIMESTAMP_LOGS 1
22#else
23#undef LF_TIMESTAMP_LOGS
24#define LF_TIMESTAMP_LOGS 0
25#endif
26
27// The default log level for any unspecified module
28#ifndef LF_LOG_LEVEL_ALL
29#ifndef NDEBUG
30#define LF_LOG_LEVEL_ALL LF_LOG_LEVEL_DEBUG
31#else
32#define LF_LOG_LEVEL_ALL LF_LOG_LEVEL_ERROR
33#endif
34#endif
35
36// Define the log level for each module. If not defined, use LF_LOG_LEVEL_ALL
37// or set to LF_LOG_LEVEL_ERROR if LF_LOG_LEVEL_ALL is not defined.
38#ifndef LF_LOG_LEVEL_ENV
39#ifdef LF_LOG_LEVEL_ALL
40#define LF_LOG_LEVEL_ENV LF_LOG_LEVEL_ALL
41#else
42#define LF_LOG_LEVEL_ENV LF_LOG_LEVEL_ERROR
43#endif
44#endif
45
46#ifndef LF_LOG_LEVEL_SCHED
47#ifdef LF_LOG_LEVEL_ALL
48#define LF_LOG_LEVEL_SCHED LF_LOG_LEVEL_ALL
49#else
50#define LF_LOG_LEVEL_SCHED LF_LOG_LEVEL_ERROR
51#endif
52#endif
53
54#ifndef LF_LOG_LEVEL_QUEUE
55#ifdef LF_LOG_LEVEL_ALL
56#define LF_LOG_LEVEL_QUEUE LF_LOG_LEVEL_ALL
57#else
58#define LF_LOG_LEVEL_QUEUE LF_LOG_LEVEL_ERROR
59#endif
60#endif
61
62#ifndef LF_LOG_LEVEL_FED
63#ifdef LF_LOG_LEVEL_ALL
64#define LF_LOG_LEVEL_FED LF_LOG_LEVEL_ALL
65#else
66#define LF_LOG_LEVEL_FED LF_LOG_LEVEL_ERROR
67#endif
68#endif
69
70#ifndef LF_LOG_LEVEL_TRIG
71#ifdef LF_LOG_LEVEL_ALL
72#define LF_LOG_LEVEL_TRIG LF_LOG_LEVEL_ALL
73#else
74#define LF_LOG_LEVEL_TRIG LF_LOG_LEVEL_ERROR
75#endif
76#endif
77
78#ifndef LF_LOG_LEVEL_PLATFORM
79#ifdef LF_LOG_LEVEL_ALL
80#define LF_LOG_LEVEL_PLATFORM LF_LOG_LEVEL_ALL
81#else
82#define LF_LOG_LEVEL_PLATFORM LF_LOG_LEVEL_ERROR
83#endif
84#endif
85
86#ifndef LF_LOG_LEVEL_CONN
87#ifdef LF_LOG_LEVEL_ALL
88#define LF_LOG_LEVEL_CONN LF_LOG_LEVEL_ALL
89#else
90#define LF_LOG_LEVEL_CONN LF_LOG_LEVEL_ERROR
91#endif
92#endif
93
94#ifndef LF_LOG_LEVEL_NET
95#ifdef LF_LOG_LEVEL_ALL
96#define LF_LOG_LEVEL_NET LF_LOG_LEVEL_ALL
97#else
98#define LF_LOG_LEVEL_NET LF_LOG_LEVEL_ERROR
99#endif
100#endif
101
102// The user can disable all logging by defining LF_LOG_DISABLE
103#if defined(LF_LOG_DISABLE)
104#define LF_LOG(level, module, fmt, ...)
105#define LF_ERR(module, fmt, ...)
106#define LF_WARN(module, fmt, ...)
107#define LF_INFO(module, fmt, ...)
108#define LF_DEBUG(module, fmt, ...)
109#else
110// Each call to LF_LOG is expanded to a this piece of code where the verbosity
111// level of the message is compared to the log level of the module. This adds
112// some overhead even if verbosity is turned down.
113#define LF_LOG(level, module, fmt, ...) \
114 do { \
115 if (level <= LF_LOG_LEVEL_##module) { \
116 log_message(level, #module, fmt, ##__VA_ARGS__); \
117 } \
118 } while (0)
119
120#define LF_ERR(module, fmt, ...) LF_LOG(LF_LOG_LEVEL_ERROR, module, fmt, ##__VA_ARGS__)
121#define LF_WARN(module, fmt, ...) LF_LOG(LF_LOG_LEVEL_WARN, module, fmt, ##__VA_ARGS__)
122#define LF_INFO(module, fmt, ...) LF_LOG(LF_LOG_LEVEL_INFO, module, fmt, ##__VA_ARGS__)
123#define LF_DEBUG(module, fmt, ...) LF_LOG(LF_LOG_LEVEL_DEBUG, module, fmt, ##__VA_ARGS__)
124
125void log_message(int level, const char *module, const char *fmt, ...);
126#endif
127
128#endif
void log_message(int level, const char *module, const char *fmt,...)