mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-28 00:10:21 +08:00
Fixed ring buffer sink
This commit is contained in:
parent
1ab59c4237
commit
1bfdff87ab
@ -10,7 +10,7 @@
|
|||||||
#include "../details/async_log_msg.h"
|
#include "../details/async_log_msg.h"
|
||||||
#include "../details/circular_q.h"
|
#include "../details/circular_q.h"
|
||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
#include "./base_sink.h"
|
#include "base_sink.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
@ -26,7 +26,7 @@ public:
|
|||||||
explicit ringbuffer_sink(size_t n_items)
|
explicit ringbuffer_sink(size_t n_items)
|
||||||
: q_{n_items} {}
|
: q_{n_items} {}
|
||||||
|
|
||||||
void drain_raw(std::function<void(const details::log_msg_buffer &)> callback) {
|
void drain_raw(std::function<void(const details::async_log_msg &)> callback) {
|
||||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||||
while (!q_.empty()) {
|
while (!q_.empty()) {
|
||||||
callback(q_.front());
|
callback(q_.front());
|
||||||
@ -46,11 +46,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sink_it_(const details::log_msg &msg) override { q_.push_back(details::log_msg_buffer{msg}); }
|
void sink_it_(const details::log_msg &msg) override { q_.push_back(details::async_log_msg{details::async_log_msg::msg_type::log, msg}); }
|
||||||
void flush_() override {}
|
void flush_() override {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
details::circular_q<details::log_msg_buffer> q_;
|
details::circular_q<details::async_log_msg> q_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ringbuffer_sink_mt = ringbuffer_sink<std::mutex>;
|
using ringbuffer_sink_mt = ringbuffer_sink<std::mutex>;
|
||||||
|
Loading…
Reference in New Issue
Block a user