mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
Unnecessary backtrace begin/end logs (#2568)
* add empty getter function to tracer * add unit test to check empty tracer Co-authored-by: Gyorgy Katona <gykatona@logmein.com>
This commit is contained in:
@@ -54,6 +54,12 @@ SPDLOG_INLINE void backtracer::push_back(const log_msg &msg)
|
||||
messages_.push_back(log_msg_buffer{msg});
|
||||
}
|
||||
|
||||
SPDLOG_INLINE bool backtracer::empty() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
return messages_.empty();
|
||||
}
|
||||
|
||||
// pop all items in the q and apply the given fun on each of them.
|
||||
SPDLOG_INLINE void backtracer::foreach_pop(std::function<void(const details::log_msg &)> fun)
|
||||
{
|
||||
|
@@ -32,6 +32,7 @@ public:
|
||||
void disable();
|
||||
bool enabled() const;
|
||||
void push_back(const log_msg &msg);
|
||||
bool empty() const;
|
||||
|
||||
// pop all items in the q and apply the given fun on each of them.
|
||||
void foreach_pop(std::function<void(const details::log_msg &)> fun);
|
||||
|
@@ -210,7 +210,7 @@ SPDLOG_INLINE void logger::flush_()
|
||||
SPDLOG_INLINE void logger::dump_backtrace_()
|
||||
{
|
||||
using details::log_msg;
|
||||
if (tracer_.enabled())
|
||||
if (tracer_.enabled() && !tracer_.empty())
|
||||
{
|
||||
sink_it_(log_msg{name(), level::info, "****************** Backtrace Start ******************"});
|
||||
tracer_.foreach_pop([this](const log_msg &msg) { this->sink_it_(msg); });
|
||||
|
Reference in New Issue
Block a user