diff --git a/log/include/gz/utils/log/Logger.hh b/log/include/gz/utils/log/Logger.hh index 3e3a491..01219b1 100644 --- a/log/include/gz/utils/log/Logger.hh +++ b/log/include/gz/utils/log/Logger.hh @@ -30,7 +30,7 @@ namespace utils { namespace log { -inline namespace GZ_UTILS_VERSION_NAMESPACE { +inline namespace GZ_UTILS_LOG_VERSION_NAMESPACE { /// \brief Gazebo console and file logging class. /// This will configure spdlog with a sane set of defaults for logging to the diff --git a/log/include/gz/utils/log/SplitSink.hh b/log/include/gz/utils/log/SplitSink.hh index 92b7235..d057cb9 100644 --- a/log/include/gz/utils/log/SplitSink.hh +++ b/log/include/gz/utils/log/SplitSink.hh @@ -116,11 +116,18 @@ using SplitConsoleSinkSt = SplitConsoleSink; /// /// This will route messages with severity (warn, err, critical) to stderr, /// and all other levels (info, debug, trace) to stdout -template +template class SplitRingBufferSink: public spdlog::sinks::base_sink { /// \brief Class constructor. - public: SplitRingBufferSink() = default; + /// \param[in] _numItems + public: explicit SplitRingBufferSink(size_t _numItems) + { + this->stdout = + std::make_shared(_numItems); + this->stderr = + std::make_shared(_numItems); + } /// \brief No copy constructor. public: SplitRingBufferSink(const SplitRingBufferSink &) = delete; @@ -134,7 +141,7 @@ class SplitRingBufferSink: public spdlog::sinks::base_sink public: std::vector last_raw_stdout( size_t _lim = 0) { - return this->stdout.last_raw(_lim); + return this->stdout->last_raw(_lim); } /// \brief ToDo. @@ -143,7 +150,7 @@ class SplitRingBufferSink: public spdlog::sinks::base_sink public: std::vector last_raw_stderr( size_t _lim = 0) { - return this->stderr.last_raw(_lim); + return this->stderr->last_raw(_lim); } /// \brief ToDo. @@ -151,7 +158,7 @@ class SplitRingBufferSink: public spdlog::sinks::base_sink /// \return public: std::vector last_formatted_stdout(size_t _lim = 0) { - return this->stdout.last_formatted(_lim); + return this->stdout->last_formatted(_lim); } /// \brief ToDo. @@ -159,7 +166,7 @@ class SplitRingBufferSink: public spdlog::sinks::base_sink /// \return public: std::vector last_formatted_stderr(size_t _lim = 0) { - return this->stderr.last_formatted(_lim); + return this->stderr->last_formatted(_lim); } /// \brief ToDo. @@ -173,17 +180,17 @@ class SplitRingBufferSink: public spdlog::sinks::base_sink _msg.level == spdlog::level::err || _msg.level == spdlog::level::critical) { - this->stderr.log(_msg); + this->stderr->log(_msg); } else - this->stdout.log(_msg); + this->stdout->log(_msg); } /// \brief Flush messages. protected: void flush_() override { - this->stdout.flush(); - this->stderr.flush(); + this->stdout->flush(); + this->stderr->flush(); } /// \brief Set the logging pattern. @@ -200,21 +207,20 @@ class SplitRingBufferSink: public spdlog::sinks::base_sink std::unique_ptr _sinkFormatter) override { spdlog::sinks::base_sink::formatter_ = std::move(_sinkFormatter); - this->stdout.set_formatter( + this->stdout->set_formatter( spdlog::sinks::base_sink::formatter_->clone()); - this->stderr.set_formatter( + this->stderr->set_formatter( spdlog::sinks::base_sink::formatter_->clone()); } /// \brief Standard output. - private: spdlog::sinks::ringbuffer_sink_st stdout {numItems}; + private: std::shared_ptr stdout; /// \brief Standard error. - private: spdlog::sinks::ringbuffer_sink_st stderr {numItems}; + private: std::shared_ptr stderr; }; -template -using SplitRingBufferSinkMt = SplitRingBufferSink; +using SplitRingBufferSinkMt = SplitRingBufferSink; } // namespace GZ_UTILS_LOG_VERSION_NAMESPACE } // namespace log diff --git a/log/src/SplitSink_TEST.cc b/log/src/SplitSink_TEST.cc index 284fe02..8a6e553 100644 --- a/log/src/SplitSink_TEST.cc +++ b/log/src/SplitSink_TEST.cc @@ -39,7 +39,7 @@ TEST(SplitConsoleSink, foo) TEST(SplitRingBufferSink, foo) { auto splitSink = - std::make_shared>(); + std::make_shared(100); auto splitSinkConsole = std::make_shared();