Commit 8d8aacf5 authored by gabime's avatar gabime

Protect from double call to enable_backtrace()

parent e085ba7f
...@@ -120,14 +120,21 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti ...@@ -120,14 +120,21 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti
set_formatter(std::move(new_formatter)); set_formatter(std::move(new_formatter));
} }
// create new backtrace sink and hand it all sinks
SPDLOG_INLINE void logger::enable_backtrace(level::level_enum trigger_level, size_t n_messages) SPDLOG_INLINE void logger::enable_backtrace(level::level_enum trigger_level, size_t n_messages)
{ {
auto backtrace_sink = std::make_shared<spdlog::sinks::backtrace_sink_mt>(trigger_level, n_messages); if(!backtrace_enabled_)
backtrace_sink->set_sinks(std::move(sinks())); {
sinks().push_back(std::move(backtrace_sink)); backtrace_enabled_ = true;
this->set_level(spdlog::level::trace); auto backtrace_sink = std::make_shared<spdlog::sinks::backtrace_sink_mt>(trigger_level, n_messages);
backtrace_sink->set_sinks(std::move(sinks()));
sinks().push_back(std::move(backtrace_sink));
this->set_level(spdlog::level::trace);
}
} }
// flush functions // flush functions
SPDLOG_INLINE void logger::flush() SPDLOG_INLINE void logger::flush()
{ {
......
...@@ -347,6 +347,7 @@ protected: ...@@ -347,6 +347,7 @@ protected:
spdlog::level_t level_{level::info}; spdlog::level_t level_{level::info};
spdlog::level_t flush_level_{level::off}; spdlog::level_t flush_level_{level::off};
err_handler custom_err_handler_{nullptr}; err_handler custom_err_handler_{nullptr};
bool backtrace_enabled_ {false};
virtual void sink_it_(const details::log_msg &msg); virtual void sink_it_(const details::log_msg &msg);
virtual void flush_(); virtual void flush_();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment