9#include <source_location>
12#include <fmt/format.h>
54 template <
typename... FmtArgs>
58 fmt::format_string<FmtArgs...>,
68 template <
typename... FmtArgs>
70 std::source_location loc,
72 fmt::format_string<FmtArgs...> fmt,
73 FmtArgs &&... args)
const
75 if (!logger_.load (std::memory_order_acquire))
77 auto msg = fmt::format (fmt, std::forward<FmtArgs> (args)...);
78 submit (loc, level, std::move (msg));
81 void init (LoggerType type);
89 std::atomic<Logger *> logger_{
nullptr };
90 std::once_flag init_flag_;
94 void submit (std::source_location loc, LogLevel level, std::string msg)
const;
97template <
typename... Tags>
inline auto log_api =
NullLogApi{};
99template <>
inline auto log_api<> = SpdlogApi{};
104init_logging (LoggerType type);
106is_logging_initialized ();
108std::vector<Utf8String>
109get_last_log_entries (
size_t count);
114template <
typename... Args>
117 std::source_location loc,
118 fmt::format_string<Args...> fmt,
121 detail::log_api<>.log (
122 loc, LogLevel::Trace, fmt, std::forward<Args> (args)...);
125template <
typename... Args>
128 std::source_location loc,
129 fmt::format_string<Args...> fmt,
132 detail::log_api<>.log (
133 loc, LogLevel::Debug, fmt, std::forward<Args> (args)...);
136template <
typename... Args>
139 std::source_location loc,
140 fmt::format_string<Args...> fmt,
143 detail::log_api<>.log (loc, LogLevel::Info, fmt, std::forward<Args> (args)...);
146template <
typename... Args>
149 std::source_location loc,
150 fmt::format_string<Args...> fmt,
153 detail::log_api<>.log (
154 loc, LogLevel::Warning, fmt, std::forward<Args> (args)...);
157template <
typename... Args>
160 std::source_location loc,
161 fmt::format_string<Args...> fmt,
164 detail::log_api<>.log (
165 loc, LogLevel::Error, fmt, std::forward<Args> (args)...);
168template <
typename... Args>
171 std::source_location loc,
172 fmt::format_string<Args...> fmt,
175 detail::log_api<>.log (
176 loc, LogLevel::Critical, fmt, std::forward<Args> (args)...);
179#define z_trace(...) \
180 ::zrythm::utils::log_trace (std::source_location::current (), __VA_ARGS__)
181#define z_debug(...) \
182 ::zrythm::utils::log_debug (std::source_location::current (), __VA_ARGS__)
184 ::zrythm::utils::log_info (std::source_location::current (), __VA_ARGS__)
185#define z_warning(...) \
186 ::zrythm::utils::log_warning (std::source_location::current (), __VA_ARGS__)
187#define z_error(...) \
188 ::zrythm::utils::log_error (std::source_location::current (), __VA_ARGS__)
189#define z_critical(...) \
190 ::zrythm::utils::log_critical (std::source_location::current (), __VA_ARGS__)
192#define z_return_val_if_fail(cond, val) \
193 if (!(cond)) [[unlikely]] \
195 z_error ("Assertion failed: {}", #cond); \
199#define z_return_if_fail(cond) z_return_val_if_fail (cond, )
201#define z_return_val_if_reached(val) \
203 z_error ("This code should not be reached"); \
207#define z_return_if_reached() z_return_val_if_reached ()
209#define z_warn_if_fail(cond) \
210 if (!(cond)) [[unlikely]] \
212 z_warning ("Assertion failed: {}", #cond); \
215#define z_warn_if_reached() z_warning ("This code should not be reached")
Lightweight UTF-8 string wrapper with safe conversions.