Mescal
Loading...
Searching...
No Matches
error.h
Go to the documentation of this file.
1
53#ifndef ERROR_H_
54#define ERROR_H_
55
57#define ATTENTION "\xe2\x9d\x97"
59#define HINT "\xe2\x9c\xa8"
61#define OK "\xE2\x9C\x85"
63#define KO "\xE2\x9D\x8C"
64
65// In X mode, all messages more severe than X are printed.
66// clang-format off
67enum debug_level {OFF, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACE};
68enum msg_level {CRITICAL_L, ERROR_L, WARNING_L, INFO_L, DEBUG_L, TRACE_L};
69// clang-format on
70
97
98#ifndef DEBUG_LEVEL
99#define DEBUG_LEVEL INFO
100#endif
101
102// __VA_OPTS__ requires C2x. Clang issues spurious warning.
103
120
121#define PRINT_ERROR(symbol, name, function, file, line, msg, ...) \
122 do { \
123 fprintf(stderr, \
124 "\n" symbol " [" name "]" \
125 " - Function %s (%s:%d) -\n " msg "\n", \
126 function, file, line __VA_OPT__(, ) __VA_ARGS__); \
127 } while (0)
128
130#define FATAL(msg, ...) \
131 do { \
132 PRINT_ERROR(KO, "FATAL", __func__, __FILE__, __LINE__, \
133 msg __VA_OPT__(, ) __VA_ARGS__); \
134 exit(EXIT_FAILURE); \
135 } while (0)
136
137#define PRINT_DEBUG(symbol, name, level, msg, ...) \
138 do { \
139 if ((int)DEBUG_LEVEL > (int)level) \
140 PRINT_ERROR(symbol, name, __func__, __FILE__, __LINE__, \
141 msg __VA_OPT__(, ) __VA_ARGS__); \
142 } while (0)
143
145#define TRACE(msg, ...) PRINT_DEBUG(OK, "TRACE", TRACE_L, msg, __VA_ARGS__)
146
148#define DEBUG(msg, ...) PRINT_DEBUG(HINT, "DEBUG", DEBUG_L, msg, __VA_ARGS__)
149
151#define INFO(msg, ...) PRINT_DEBUG(HINT, "INFO", INFO_L, msg, __VA_ARGS__)
152
154#define WARNING(msg, ...) \
155 PRINT_DEBUG(ATTENTION, "WARNING", WARNING_L, msg, __VA_ARGS__)
156
158#define ERROR(msg, ...) \
159 PRINT_DEBUG(ATTENTION, "ERROR", ERROR_L, msg, __VA_ARGS__)
160
162#define CRITICAL(msg, ...) \
163 PRINT_DEBUG(KO, "CRITICAL", CRITICAL_L, msg, __VA_ARGS__)
164
165#endif // ERROR_H_
#define TRACE(msg,...)
Prints a TRACE message.
Definition error.h:145
#define DEBUG(msg,...)
Print a DEBUG message.
Definition error.h:148
#define INFO(msg,...)
Print an INFO message.
Definition error.h:151
#define WARNING(msg,...)
Print a WARNING message.
Definition error.h:154
#define CRITICAL(msg,...)
Print a CRITICAL message.
Definition error.h:162
#define ERROR(msg,...)
Print an ERROR message.
Definition error.h:158