Commit 62e09e73 authored by Václav Šmilauer's avatar Václav Šmilauer

defer formatting, use log_msg_buffer for intermediate storage

parent daef0a23
......@@ -16,15 +16,13 @@ namespace sinks {
template<typename Mutex>
SPDLOG_INLINE ringbuffer_sink<Mutex>::ringbuffer_sink(size_t buf_size)
{
buf=details::circular_q<std::string>(buf_size);
buf_=details::circular_q<details::log_msg_buffer>(buf_size);
}
template<typename Mutex>
SPDLOG_INLINE void ringbuffer_sink<Mutex>::sink_it_(const details::log_msg &msg)
{
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
buf.push_back(fmt::to_string(formatted));
buf_.push_back(details::log_msg_buffer{msg});
}
template<typename Mutex>
......@@ -34,9 +32,11 @@ SPDLOG_INLINE std::vector<std::string> ringbuffer_sink<Mutex>::last(size_t lim)
std::vector<std::string> ret;
ret.reserve(lim);
size_t num=0;
for(size_t i=0; i<buf.size(); i++){
for(size_t i=0; i<buf_.size(); i++){
num++;
ret.push_back(buf.at(i));
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(buf_.at(i), formatted);
ret.push_back(fmt::to_string(formatted));
if(lim>0 && num==lim) break;
}
return ret;
......
......@@ -7,6 +7,7 @@
#include "spdlog/sinks/base_sink.h"
#include "spdlog/details/synchronous_factory.h"
#include "spdlog/details/circular_q.h"
#include "spdlog/details/log_msg_buffer.h"
#include <mutex>
#include <string>
......@@ -29,7 +30,7 @@ protected:
void flush_() override {};
private:
details::circular_q<std::string> buf;
details::circular_q<details::log_msg_buffer> buf_;
};
using ringbuffer_sink_mt = ringbuffer_sink<std::mutex>;
......
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