mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-23 22:22:05 +08:00
defer formatting, use log_msg_buffer for intermediate storage
This commit is contained in:
parent
daef0a2374
commit
62e09e73f7
@ -16,15 +16,13 @@ namespace sinks {
|
|||||||
template<typename Mutex>
|
template<typename Mutex>
|
||||||
SPDLOG_INLINE ringbuffer_sink<Mutex>::ringbuffer_sink(size_t buf_size)
|
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>
|
template<typename Mutex>
|
||||||
SPDLOG_INLINE void ringbuffer_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
SPDLOG_INLINE void ringbuffer_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||||
{
|
{
|
||||||
memory_buf_t formatted;
|
buf_.push_back(details::log_msg_buffer{msg});
|
||||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
|
||||||
buf.push_back(fmt::to_string(formatted));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Mutex>
|
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;
|
std::vector<std::string> ret;
|
||||||
ret.reserve(lim);
|
ret.reserve(lim);
|
||||||
size_t num=0;
|
size_t num=0;
|
||||||
for(size_t i=0; i<buf.size(); i++){
|
for(size_t i=0; i<buf_.size(); i++){
|
||||||
num++;
|
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;
|
if(lim>0 && num==lim) break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "spdlog/sinks/base_sink.h"
|
#include "spdlog/sinks/base_sink.h"
|
||||||
#include "spdlog/details/synchronous_factory.h"
|
#include "spdlog/details/synchronous_factory.h"
|
||||||
#include "spdlog/details/circular_q.h"
|
#include "spdlog/details/circular_q.h"
|
||||||
|
#include "spdlog/details/log_msg_buffer.h"
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -29,7 +30,7 @@ protected:
|
|||||||
void flush_() override {};
|
void flush_() override {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
details::circular_q<std::string> buf;
|
details::circular_q<details::log_msg_buffer> buf_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ringbuffer_sink_mt = ringbuffer_sink<std::mutex>;
|
using ringbuffer_sink_mt = ringbuffer_sink<std::mutex>;
|
||||||
|
Loading…
Reference in New Issue
Block a user