21 #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
23 # error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
30 #ifndef SPDLOG_NO_EXCEPTIONS
31 # define SPDLOG_LOGGER_CATCH(location) \
32 catch (const std::exception &ex) \
34 if (location.filename) \
36 err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
40 err_handler_(ex.what()); \
45 err_handler_("Rethrowing unknown exception in logger"); \
49 # define SPDLOG_LOGGER_CATCH(location)
59 : name_(
std::move(name))
66 : name_(
std::move(name))
72 :
logger(
std::move(name), {std::move(single_sink)})
80 virtual ~
logger() =
default;
87 template<
typename... Args>
90 log_(loc, lvl,
fmt, std::forward<Args>(args)...);
93 template<
typename... Args>
109 log(loc, lvl,
"{}", msg);
115 bool traceback_enabled = tracer_.enabled();
116 if (!log_enabled && !traceback_enabled)
122 log_it_(log_msg, log_enabled, traceback_enabled);
128 bool traceback_enabled = tracer_.enabled();
129 if (!log_enabled && !traceback_enabled)
135 log_it_(log_msg, log_enabled, traceback_enabled);
143 template<
typename... Args>
149 template<
typename... Args>
155 template<
typename... Args>
161 template<
typename... Args>
167 template<
typename... Args>
173 template<
typename... Args>
179 #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
180 template<
typename... Args>
183 log_(loc, lvl,
fmt, std::forward<Args>(args)...);
186 template<
typename... Args>
189 log(source_loc{}, lvl,
fmt, std::forward<Args>(args)...);
192 void log(log_clock::time_point log_time, source_loc loc,
level::level_enum lvl, wstring_view_t msg)
195 bool traceback_enabled = tracer_.enabled();
196 if (!log_enabled && !traceback_enabled)
202 details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf);
203 details::log_msg log_msg(log_time, loc, name_, lvl,
string_view_t(buf.data(), buf.size()));
204 log_it_(log_msg, log_enabled, traceback_enabled);
210 bool traceback_enabled = tracer_.enabled();
211 if (!log_enabled && !traceback_enabled)
217 details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf);
218 details::log_msg log_msg(loc, name_, lvl,
string_view_t(buf.data(), buf.size()));
219 log_it_(log_msg, log_enabled, traceback_enabled);
224 log(source_loc{}, lvl, msg);
227 template<
typename... Args>
228 void trace(wformat_string_t<Args...>
fmt, Args &&... args)
233 template<
typename... Args>
234 void debug(wformat_string_t<Args...>
fmt, Args &&... args)
239 template<
typename... Args>
240 void info(wformat_string_t<Args...>
fmt, Args &&... args)
245 template<
typename... Args>
246 void warn(wformat_string_t<Args...>
fmt, Args &&... args)
251 template<
typename... Args>
252 void error(wformat_string_t<Args...>
fmt, Args &&... args)
257 template<
typename... Args>
258 void critical(wformat_string_t<Args...>
fmt, Args &&... args)
303 return msg_level >= level_.load(std::memory_order_relaxed);
309 return tracer_.enabled();
316 const std::string &name()
const;
336 const std::vector<sink_ptr> &sinks()
const;
338 std::vector<sink_ptr> &sinks();
344 virtual std::shared_ptr<logger> clone(std::string logger_name);
355 template<
typename... Args>
359 bool traceback_enabled = tracer_.
enabled();
360 if (!log_enabled && !traceback_enabled)
366 #ifdef SPDLOG_USE_STD_FORMAT
373 log_it_(log_msg, log_enabled, traceback_enabled);
378 #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
379 template<
typename... Args>
383 bool traceback_enabled = tracer_.
enabled();
384 if (!log_enabled && !traceback_enabled)
392 # ifdef SPDLOG_USE_STD_FORMAT
399 details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf);
400 details::log_msg log_msg(loc, name_, lvl,
string_view_t(buf.data(), buf.size()));
401 log_it_(log_msg, log_enabled, traceback_enabled);
411 bool traceback_enabled = tracer_.
enabled();
412 if (!log_enabled && !traceback_enabled)
419 details::os::wstr_to_utf8buf(msg, buf);
420 details::log_msg log_msg(loc, name_, lvl,
string_view_t(buf.data(), buf.size()));
421 log_it_(log_msg, log_enabled, traceback_enabled);
426 #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
430 void log_it_(
const details::log_msg &log_msg,
bool log_enabled,
bool traceback_enabled);
431 virtual void sink_it_(
const details::log_msg &msg);
432 virtual void flush_();
433 void dump_backtrace_();
434 bool should_flush_(
const details::log_msg &msg);
438 void err_handler_(
const std::string &msg);
441 void swap(logger &a, logger &b);
445 #ifdef SPDLOG_HEADER_ONLY