9#define DEBUG_NOEXCEPT_OFF noexcept
11#define DEBUG_NOEXCEPT_OFF
29void set_log_level(
const logging::level log_level)
noexcept;
30void increase_log_level() noexcept;
31void decrease_log_level() noexcept;
32logging::level get_log_level() noexcept;
33inline
bool should_log(const logging::level log_level) noexcept
35 return get_log_level() >= log_level;
37inline bool should_not_log(
const logging::level log_level)
noexcept
39 return get_log_level() < log_level;
41int open_log_file(
const char* filename)
noexcept;
42int close_log_file() noexcept;
45[[nodiscard]]
string output_no_check(logging::level log_level, const
string msg) DEBUG_NOEXCEPT_OFF;
46template <typename... Args>
47[[nodiscard]] inline
string output_no_check(
48 logging::level log_level,
49 std::format_string<Args...> format,
53 return output_no_check(log_level, std::format(format, std::forward<Args>(args)...));
55template <
typename... Args>
56[[nodiscard]]
inline string output(
57 logging::level log_level,
58 std::format_string<Args...> format,
62 if (should_not_log(log_level))
66 return output_no_check(log_level, format, std::forward<Args>(args)...);
68template <
typename... Args>
69inline void extensive(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
71 std::ignore = output(logging::level::extensive, format, std::forward<Args>(args)...);
73template <
typename... Args>
74inline void verbose(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
76 std::ignore = output(logging::level::verbose, format, std::forward<Args>(args)...);
78template <
typename... Args>
79inline void debug(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
81 std::ignore = output(logging::level::debug, format, std::forward<Args>(args)...);
83template <
typename... Args>
84inline void info(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
86 std::ignore = output(logging::level::info, format, std::forward<Args>(args)...);
88template <
typename... Args>
89inline void note(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
91 std::ignore = output(logging::level::note, format, std::forward<Args>(args)...);
93template <
typename... Args>
94inline void warning(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
96 std::ignore = output(logging::level::warning, format, std::forward<Args>(args)...);
98template <
typename... Args>
99inline void error(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
101 std::ignore = output(logging::level::error, format, std::forward<Args>(args)...);
103template <
typename... Args>
104inline int fatal(std::format_string<Args...> format, Args&&... args) DEBUG_NOEXCEPT_OFF
106 auto msg = output(logging::level::fatal, format, std::forward<Args>(args)...);
109 throw std::runtime_error(msg);
115inline int fatal(
const std::exception& ex) DEBUG_NOEXCEPT_OFF
117 std::ignore = output(logging::level::fatal,
"{:s}", ex.what());
126template <
typename... Args>
127inline int fatal(
const std::exception& ex, std::format_string<Args...> format, Args&&... args)
130 std::ignore = output(logging::level::fatal, format, std::forward<Args>(args)...);
133template <
typename... Args>
134inline constexpr void check_fatal(
136 std::format_string<Args...> format,
144 fatal(format, std::forward<Args>(args)...);
147inline void check_equal(
const T lhs,
const T rhs,
const char* name) DEBUG_NOEXCEPT_OFF
149 check_fatal(lhs != rhs,
"Expected {:s} to be {} but got {}", name, rhs, lhs);
151inline void check_equal(
const char* lhs,
const char* rhs,
const char* name) DEBUG_NOEXCEPT_OFF
153 check_fatal(0 != strcmp(lhs, rhs),
"Expected {:s} to be {:s} got {:s}", name, rhs, lhs);
155inline void check_equal(
const bool lhs,
const bool rhs,
const char* name) DEBUG_NOEXCEPT_OFF
159 "Expected {:s} to be {:s} but got {:s}",
161 lhs ?
"true" :
"false",
162 rhs ?
"true" :
"false"
166inline void check_equal_verbose(
167 const logging::level log_level,
173 check_equal(lhs, rhs, name);
174 std::ignore = output(log_level,
"{:s} matches", name);
176inline void check_tolerance(
177 const MathSize epsilon,
183 const auto difference = abs(lhs - rhs);
185 difference >= epsilon,
186 "Difference too big for {:s}: ({:g} > {:g}) for {:g} vs {:g}",