reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
logging_macros.h
Go to the documentation of this file.
1
11#ifndef LOGGING_MACROS_H
12#define LOGGING_MACROS_H
13#include "logging.h"
14#include <stdbool.h>
15
17#ifndef LOG_LEVEL
18#define LOG_LEVEL LOG_LEVEL_INFO
19#endif
20
21// To prevent warnings "conditional expression is constant", we define static booleans
22// here instead of directly testing LOG_LEVEL in the if statements in the macros below.
25
45#define LF_PRINT_LOG(format, ...) \
46 do { \
47 if (_lf_log_level_is_log) { \
48 lf_print_log(format, ##__VA_ARGS__); \
49 } \
50 } while (0)
51
72#define LF_PRINT_DEBUG(format, ...) \
73 do { \
74 if (_lf_log_level_is_debug) { \
75 lf_print_debug(format, ##__VA_ARGS__); \
76 } \
77 } while (0)
78
79#if defined(NDEBUG)
80#define LF_ASSERT(condition, format, ...) (void)(condition)
81#define LF_ASSERTN(condition, format, ...) (void)(condition)
82#define LF_ASSERT_NON_NULL(pointer) (void)(pointer)
83#else
84
101#define LF_ASSERT(condition, format, ...) \
102 do { \
103 if (!(condition)) { \
104 lf_print_error_and_exit("`" format "`. Failed assertion in %s:%d(%s):(" #condition ") != true`", ##__VA_ARGS__, \
105 __FILE__, __LINE__, __func__); \
106 } \
107 } while (0)
108
124#define LF_ASSERTN(condition, format, ...) \
125 do { \
126 if (condition) { \
127 lf_print_error_and_exit("`" format "`. Failed assertion in %s:%d(%s):(" #condition ") != false`", ##__VA_ARGS__, \
128 __FILE__, __LINE__, __func__); \
129 } \
130 } while (0)
131
142
143#define LF_ASSERT_NON_NULL(pointer) \
144 do { \
145 if (!(pointer)) { \
146 lf_print_error_and_exit("`Out of memory?` Assertion failed in %s:%d(%s):`" #pointer " == NULL`", __FILE__, \
147 __LINE__, __func__); \
148 } \
149 } while (0)
150#endif // NDEBUG
151
164#define LF_TEST(condition, format, ...) \
165 do { \
166 if (!(condition)) { \
167 lf_print_error_and_exit("`" format "`. Failed assertion in %s:%d(%s):(" #condition ") != true`", ##__VA_ARGS__, \
168 __FILE__, __LINE__, __func__); \
169 } \
170 } while (0)
171
172#endif // LOGGING_MACROS_H
#define LOG_LEVEL_DEBUG
Debug log level.
Definition logging.h:77
#define LOG_LEVEL_LOG
Log log level.
Definition logging.h:69
Logging API for the C target of Lingua Franca.
#define LOG_LEVEL
Default log level.
Definition logging_macros.h:18
static const bool _lf_log_level_is_debug
Definition logging_macros.h:24
static const bool _lf_log_level_is_log
Definition logging_macros.h:23