mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 10:29:02 +08:00
Refactored logger
This commit is contained in:
@@ -73,11 +73,11 @@ public:
|
||||
|
||||
void swap(spdlog::logger &other) SPDLOG_NOEXCEPT;
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
void log(source_loc loc, level::level_enum lvl, string_view_t fmt, const Args &... args)
|
||||
{
|
||||
auto level_enabled = should_log(lvl);
|
||||
if (!level_enabled && !tracer_)
|
||||
if (!should_log(lvl) && !tracer_.enabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -86,14 +86,7 @@ public:
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, fmt, args...);
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
if (level_enabled)
|
||||
{
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
if (tracer_)
|
||||
{
|
||||
tracer_.push_back(log_msg);
|
||||
}
|
||||
log_it_(log_msg);
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH()
|
||||
}
|
||||
@@ -150,24 +143,14 @@ public:
|
||||
template<class T, typename std::enable_if<std::is_convertible<const T &, spdlog::string_view_t>::value, T>::type * = nullptr>
|
||||
void log(source_loc loc, level::level_enum lvl, const T &msg)
|
||||
{
|
||||
auto level_enabled = should_log(lvl);
|
||||
if (!level_enabled && !tracer_)
|
||||
if (!should_log(lvl) && !tracer_.enabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
SPDLOG_TRY
|
||||
{
|
||||
details::log_msg log_msg(loc, name_, lvl, msg);
|
||||
if (level_enabled)
|
||||
{
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
if (tracer_)
|
||||
{
|
||||
tracer_.push_back(log_msg);
|
||||
}
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH()
|
||||
|
||||
details::log_msg log_msg(loc, name_, lvl, msg);
|
||||
log_it_(log_msg);
|
||||
|
||||
}
|
||||
|
||||
void log(level::level_enum lvl, string_view_t msg)
|
||||
@@ -228,8 +211,7 @@ public:
|
||||
template<typename... Args>
|
||||
void log(source_loc loc, level::level_enum lvl, wstring_view_t fmt, const Args &... args)
|
||||
{
|
||||
auto level_enabled = should_log(lvl);
|
||||
if (!level_enabled && !tracer_)
|
||||
if (!should_log(lvl) && !tracer_.enabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -242,15 +224,7 @@ public:
|
||||
memory_buf_t buf;
|
||||
details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf);
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
|
||||
if (level_enabled)
|
||||
{
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
if (tracer_)
|
||||
{
|
||||
tracer_.push_back(log_msg);
|
||||
}
|
||||
log_it_(log_msg);
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH()
|
||||
}
|
||||
@@ -301,7 +275,7 @@ public:
|
||||
template<class T, typename std::enable_if<is_convertible_to_wstring_view<const T &>::value, T>::type * = nullptr>
|
||||
void log(source_loc loc, level::level_enum lvl, const T &msg)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
if (!should_log(lvl) && !tracer_.enabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -310,9 +284,8 @@ public:
|
||||
{
|
||||
memory_buf_t buf;
|
||||
details::os::wstr_to_utf8buf(msg, buf);
|
||||
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
sink_it_(log_msg);
|
||||
log_it_(log_msg);
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH()
|
||||
}
|
||||
@@ -367,6 +340,9 @@ protected:
|
||||
err_handler custom_err_handler_{nullptr};
|
||||
details::backtracer tracer_;
|
||||
|
||||
// log the given message (if the given log level is high enough),
|
||||
// and save backtrace (if backtrace is enabled).
|
||||
void log_it_(const details::log_msg &log_msg);
|
||||
virtual void sink_it_(const details::log_msg &msg);
|
||||
virtual void flush_();
|
||||
void dump_backtrace_();
|
||||
|
Reference in New Issue
Block a user