spdlog
Loading...
Searching...
No Matches
test_sink.h
Go to the documentation of this file.
1//
2// Copyright(c) 2018 Gabi Melman.
3// Distributed under the MIT License (http://opensource.org/licenses/MIT)
4//
5
6#pragma once
7
10#include "spdlog/fmt/fmt.h"
11#include <chrono>
12#include <mutex>
13#include <thread>
14
15namespace spdlog {
16namespace sinks {
17
18template<class Mutex>
19class test_sink : public base_sink<Mutex>
20{
21 const size_t lines_to_save = 100;
22
23public:
29
35
41
42 // return last output without the eol
48
49protected:
50 void sink_it_(const details::log_msg &msg) override
51 {
52 memory_buf_t formatted;
53 base_sink<Mutex>::formatter_->format(msg, formatted);
54 // save the line without the eol
55 auto eol_len = strlen(details::os::default_eol);
57 {
58 lines_.emplace_back(formatted.begin(), formatted.end() - eol_len);
59 }
62 }
63
64 void flush_() override
65 {
67 }
68
69 size_t msg_counter_{0};
70 size_t flush_counter_{0};
73};
74
77
78} // namespace sinks
79} // namespace spdlog
void flush_() override
Definition test_sink.h:64
const size_t lines_to_save
Definition test_sink.h:21
void sink_it_(const details::log_msg &msg) override
Definition test_sink.h:50
std::vector< std::string > lines()
Definition test_sink.h:43
std::chrono::milliseconds delay_
Definition test_sink.h:71
std::vector< std::string > lines_
Definition test_sink.h:72
void set_delay(std::chrono::milliseconds delay)
Definition test_sink.h:36
T emplace_back(T... args)
static SPDLOG_CONSTEXPR const char * default_eol
Definition details/os.h:32
Definition async.h:25
fmt::basic_memory_buffer< char, 250 > memory_buf_t
Definition common.h:116
T size(T... args)
T sleep_for(T... args)