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