reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
logging_macros.h File Reference
#include "logging.h"

Go to the source code of this file.

Macros

#define LOG_LEVEL   LOG_LEVEL_INFO
 
#define LF_PRINT_LOG(format, ...)
 
#define LF_PRINT_DEBUG(format, ...)
 
#define LF_ASSERT(condition, format, ...)
 
#define LF_ASSERTN(condition, format, ...)
 
#define LF_ASSERT_NON_NULL(pointer)
 

Macro Definition Documentation

◆ LF_ASSERT

#define LF_ASSERT ( condition,
format,
... )
Value:
do { \
if (!(condition)) { \
lf_print_error_and_exit("`" format "`. Failed assertion in %s:%d(%s):(" #condition ") != true`", ##__VA_ARGS__, \
} \
} while (0)
return address
Definition hashmap.h:74

Assertion handling. LF_ASSERT can be used as a shorthand for verifying a condition and calling lf_print_error_and_exit if it is not true. The LF_ASSERT version requires that the condition evaluate to true (non-zero), whereas the LF_ASSERTN version requires that the condition evaluate to false (zero). These are optimized to execute the condition argument but not check the result if the NDEBUG flag is defined. The NDEBUG flag will be defined if the user specifies build-type: Release in the target properties of the LF program.

LF_ASSERT_NON_NULL can be used to verify that a pointer is not NULL. It differs from LF_ASSERT in that it does nothing at all if the NDEBUG flag is defined.

◆ LF_ASSERT_NON_NULL

#define LF_ASSERT_NON_NULL ( pointer)
Value:
do { \
if (!(pointer)) { \
lf_print_error_and_exit("`Out of memory?` Assertion failed in %s:%d(%s):`" #pointer " == NULL`", __FILE__, \
} \
} while (0)

◆ LF_ASSERTN

#define LF_ASSERTN ( condition,
format,
... )
Value:
do { \
if (condition) { \
lf_print_error_and_exit("`" format "`. Failed assertion in %s:%d(%s):(" #condition ") != false`", ##__VA_ARGS__, \
} \
} while (0)

◆ LF_PRINT_DEBUG

#define LF_PRINT_DEBUG ( format,
... )
Value:
do { \
} \
} while (0)
#define LOG_LEVEL_DEBUG
Definition logging.h:28
#define LOG_LEVEL
Definition logging_macros.h:12

A macro used to print useful debug information. It can be enabled by setting the target property 'logging' to 'DEBUG' or by defining LOG_LEVEL to 2 in the top-level preamble. The input to this macro is exactly like printf: (format, ...). "DEBUG: " is prepended to the beginning of the message and a newline is appended to the end of the message.

Note
This macro is non-empty even if LOG_LEVEL is not defined in user-code. This is to ensure that the compiler will still parse the predicate inside (...) to prevent LF_PRINT_DEBUG statements to fall out of sync with the rest of the code. This should have a negligible impact on performance if compiler optimization (e.g., -O2 for gcc) is used as long as the arguments passed to it do not themselves incur significant overhead to evaluate.

◆ LF_PRINT_LOG

#define LF_PRINT_LOG ( format,
... )
Value:
do { \
} \
} while (0)
#define LOG_LEVEL_LOG
Definition logging.h:27

A macro used to print useful logging information. It can be enabled by setting the target property 'logging' to 'LOG' or by defining LOG_LEVEL to LOG_LEVEL_LOG or LOG_LEVEL_DEBUG in the top-level preamble. The input to this macro is exactly like printf: (format, ...). "LOG: " is prepended to the beginning of the message and a newline is appended to the end of the message.

Note
This macro is non-empty even if LOG_LEVEL is not defined in user-code. This is to ensure that the compiler will still parse the predicate inside (...) to prevent LF_PRINT_LOG statements to fall out of sync with the rest of the code. This should have a negligible impact on performance if compiler optimization (e.g., -O2 for gcc) is used as long as the arguments passed to it do not themselves incur significant overhead to evaluate.

◆ LOG_LEVEL

#define LOG_LEVEL   LOG_LEVEL_INFO

Non-C implementations (which cannot benefit from the C preprocessor) should ignore this file, or merely use it as a suggestion for similar behavior that they should implement using whatever metaprogramming facilities their implementation provides in place of the preprocessor. Default log level.