diff --git a/include/spdlog/logger-inl.h b/include/spdlog/logger-inl.h index d86cba77..3bf05df2 100644 --- a/include/spdlog/logger-inl.h +++ b/include/spdlog/logger-inl.h @@ -120,14 +120,21 @@ SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type ti 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) { - auto backtrace_sink = std::make_shared(trigger_level, n_messages); - backtrace_sink->set_sinks(std::move(sinks())); - sinks().push_back(std::move(backtrace_sink)); - this->set_level(spdlog::level::trace); + if(!backtrace_enabled_) + { + backtrace_enabled_ = true; + auto backtrace_sink = std::make_shared(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 SPDLOG_INLINE void logger::flush() { diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index b0f26edf..778f7976 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -347,6 +347,7 @@ protected: spdlog::level_t level_{level::info}; spdlog::level_t flush_level_{level::off}; err_handler custom_err_handler_{nullptr}; + bool backtrace_enabled_ {false}; virtual void sink_it_(const details::log_msg &msg); virtual void flush_();