preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LogMacros.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "utils/fmt.hpp"
5
6#define PRECICE_LOG_LOCATION \
7 precice::logging::LogLocation \
8 { \
9 __FILE__, __LINE__, __func__ \
10 }
11
12#define PRECICE_WARN(...) _log.warning(PRECICE_LOG_LOCATION, precice::utils::format_or_error(__VA_ARGS__))
13
14#define PRECICE_INFO(...) _log.info(PRECICE_LOG_LOCATION, precice::utils::format_or_error(__VA_ARGS__))
15
16#define PRECICE_ERROR(...) ::precice::logging::logErrorAndThrow<::precice::Error>(_log, PRECICE_LOG_LOCATION, precice::utils::format_or_error(__VA_ARGS__))
17
18#define PRECICE_WARN_IF(condition, ...) \
19 do { \
20 if (condition) { \
21 PRECICE_WARN(__VA_ARGS__); \
22 } \
23 } while (false)
24
25#define PRECICE_INFO_IF(condition, ...) \
26 do { \
27 if (condition) { \
28 PRECICE_INFO(__VA_ARGS__); \
29 } \
30 } while (false)
31
32#define PRECICE_CHECK(check, ...) \
33 do { \
34 if (!(check)) { \
35 PRECICE_ERROR(__VA_ARGS__); \
36 } \
37 } while (false)
38
39// Debug logging is disabled in release (NDEBUG) builds by default.
40// To enable it anyhow, enable the CMake option PRECICE_RELEASE_WITH_DEBUG_LOG.
41
42#if defined(NDEBUG) && !defined(PRECICE_RELEASE_WITH_DEBUG_LOG)
43#define PRECICE_NO_DEBUG_LOG
44#endif
45
46#ifdef PRECICE_NO_DEBUG_LOG
47
48#include "utils/ignore.hpp"
49
50#define PRECICE_DEBUG(...) \
51 ::precice::utils::ignore(__VA_ARGS__)
52
53#define PRECICE_DEBUG_IF(...) \
54 ::precice::utils::ignore(__VA_ARGS__)
55
56#define PRECICE_TRACE(...) \
57 ::precice::utils::ignore(__VA_ARGS__)
58
59#else // PRECICE_NO_DEBUG_LOG
60
61#define PRECICE_DEBUG(...) _log.debug(PRECICE_LOG_LOCATION, precice::utils::format_or_error(__VA_ARGS__))
62
63#define PRECICE_DEBUG_IF(condition, ...) \
64 do { \
65 if (condition) { \
66 PRECICE_DEBUG(__VA_ARGS__); \
67 } \
68 } while (false)
69
70#endif // ! PRECICE_NO_DEBUG_LOG
71
72// Trace logging is disabled in release (NDEBUG) builds by default.
73// To enable it anyhow, enable the CMake option PRECICE_RELEASE_WITH_TRACE_LOG.
74
75#if defined(NDEBUG) && !defined(PRECICE_RELEASE_WITH_TRACE_LOG)
76#define PRECICE_NO_TRACE_LOG
77#endif
78
79#ifdef PRECICE_NO_TRACE_LOG
80
81#include "utils/ignore.hpp"
82
83#define PRECICE_TRACE(...) \
84 ::precice::utils::ignore(__VA_ARGS__)
85
86#else // PRECICE_NO_TRACE_LOG
87
88#include "logging/Tracer.hpp"
90
91// Do not put do {...} while (false) here, it will destroy the _tracer_ right after creation
92#define PRECICE_TRACE(...) \
93 precice::logging::Tracer _tracer_(_log, PRECICE_LOG_LOCATION); \
94 _log.trace(PRECICE_LOG_LOCATION, std::string{"Entering "} + __func__ + PRECICE_LOG_ARGUMENTS(__VA_ARGS__))
95
96#endif // ! PRECICE_NO_TRACE_LOG