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() \
32 catch (const std::exception &ex) \
34 err_handler_(ex.what()); \
38 err_handler_("Rethrowing unknown exception in logger"); \
42# define SPDLOG_LOGGER_CATCH()
80 template<
typename... Args>
86 template<
typename... Args>
99 template<class T, typename std::enable_if<std::is_convertible<const T &, spdlog::string_view_t>::value,
int>
::type = 0>
106 template<class T, typename std::enable_if<!is_convertible_to_any_format_string<const T &>::value,
int>
::type = 0>
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>
144 void trace(fmt::format_string<Args...>
fmt, Args &&...args)
149 template<
typename... Args>
150 void debug(fmt::format_string<Args...>
fmt, Args &&...args)
155 template<
typename... Args>
156 void info(fmt::format_string<Args...>
fmt, Args &&...args)
161 template<
typename... Args>
162 void warn(fmt::format_string<Args...>
fmt, Args &&...args)
167 template<
typename... Args>
168 void error(fmt::format_string<Args...>
fmt, Args &&...args)
173 template<
typename... Args>
179#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
180 template<
typename... Args>
186 template<
typename... Args>
187 void log(source_loc loc, level::level_enum lvl, fmt::wformat_string<Args...>
fmt, Args &&...args)
192 template<
typename... Args>
193 void trace(fmt::wformat_string<Args...>
fmt, Args &&...args)
198 template<
typename... Args>
199 void debug(fmt::wformat_string<Args...>
fmt, Args &&...args)
204 template<
typename... Args>
205 void info(fmt::wformat_string<Args...>
fmt, Args &&...args)
210 template<
typename... Args>
211 void warn(fmt::wformat_string<Args...>
fmt, Args &&...args)
216 template<
typename... Args>
217 void error(fmt::wformat_string<Args...>
fmt, Args &&...args)
222 template<
typename... Args>
223 void critical(fmt::wformat_string<Args...>
fmt, Args &&...args)
232 log(level::trace, msg);
238 log(level::debug, msg);
244 log(level::info, msg);
250 log(level::warn, msg);
256 log(level::err, msg);
262 log(level::critical, msg);
274 return tracer_.enabled();
320 template<
typename... Args>
324 bool traceback_enabled = tracer_.
enabled();
325 if (!log_enabled && !traceback_enabled)
332 fmt::detail::vformat_to(buf,
fmt, fmt::make_format_args(args...));
334 log_it_(log_msg, log_enabled, traceback_enabled);
339#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
340 template<
typename... Args>
344 bool traceback_enabled = tracer_.
enabled();
345 if (!log_enabled && !traceback_enabled)
352 fmt::wmemory_buffer wbuf;
353 fmt::detail::vformat_to(wbuf,
fmt, fmt::make_format_args<fmt::wformat_context>(args...));
355 details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf);
356 details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
357 log_it_(log_msg, log_enabled, traceback_enabled);
363 template<class T, typename std::enable_if<std::is_convertible<const T &, spdlog::wstring_view_t>::value,
int>
::type = 0>
364 void log_(source_loc loc, level::level_enum lvl,
const T &msg)
367 bool traceback_enabled = tracer_.
enabled();
368 if (!log_enabled && !traceback_enabled)
375 details::os::wstr_to_utf8buf(msg, buf);
376 details::log_msg log_msg(loc, name_, lvl,
string_view_t(buf.data(), buf.size()));
377 log_it_(log_msg, log_enabled, traceback_enabled);
386 void log_it_(
const details::log_msg &log_msg,
bool log_enabled,
bool traceback_enabled);
387 virtual void sink_it_(
const details::log_msg &msg);
388 virtual void flush_();
389 void dump_backtrace_();
390 bool should_flush_(
const details::log_msg &msg);
397void swap(logger &a, logger &b);
401#ifdef SPDLOG_HEADER_ONLY
void log(source_loc loc, level::level_enum lvl, const T &msg)
void info(fmt::format_string< Args... > fmt, Args &&...args)
bool should_backtrace() const
void log(level::level_enum lvl, const T &msg)
void log(log_clock::time_point log_time, source_loc loc, level::level_enum lvl, string_view_t msg)
std::vector< sink_ptr > sinks_
void log_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args)
void critical(const T &msg)
void error(fmt::format_string< Args... > fmt, Args &&...args)
logger(std::string name, It begin, It end)
logger(std::string name, sink_ptr single_sink)
virtual ~logger()=default
void warn(fmt::format_string< Args... > fmt, Args &&...args)
void trace(fmt::format_string< Args... > fmt, Args &&...args)
void debug(fmt::format_string< Args... > fmt, Args &&...args)
void log(source_loc loc, level::level_enum lvl, fmt::format_string< Args... > fmt, Args &&...args)
bool should_log(level::level_enum msg_level) const
details::backtracer tracer_
void log(level::level_enum lvl, fmt::format_string< Args... > fmt, Args &&...args)
void log(level::level_enum lvl, string_view_t msg)
void critical(fmt::format_string< Args... > fmt, Args &&...args)
void log(source_loc loc, level::level_enum lvl, string_view_t msg)
logger(std::string name, sinks_init_list sinks)
#define SPDLOG_LOGGER_CATCH()
SPDLOG_INLINE void disable_backtrace()
SPDLOG_INLINE void set_level(level::level_enum log_level)
fmt::basic_string_view< wchar_t > wstring_view_t
SPDLOG_INLINE void enable_backtrace(size_t n_messages)
SPDLOG_INLINE void swap(logger &a, logger &b)
SPDLOG_INLINE void set_error_handler(void(*handler)(const std::string &msg))
SPDLOG_INLINE void dump_backtrace()
fmt::basic_string_view< char > string_view_t
SPDLOG_INLINE void flush_on(level::level_enum log_level)
SPDLOG_INLINE void set_formatter(std::unique_ptr< spdlog::formatter > formatter)
SPDLOG_INLINE bool should_log(level::level_enum log_level)
SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type)
fmt::basic_memory_buffer< char, 250 > memory_buf_t