update and change how we build with spdlog

This commit is contained in:
Benjamin Sergeant
2019-09-29 11:13:24 -07:00
parent 3c8cd6289b
commit 3a91894d62
156 changed files with 28175 additions and 19817 deletions

View File

@ -7,7 +7,7 @@
#include "spdlog/details/null_mutex.h"
#include "spdlog/sinks/base_sink.h"
#include "spdlog/fmt/fmt.h"
#include <chrono>
#include <mutex>
#include <thread>
@ -18,6 +18,8 @@ namespace sinks {
template<class Mutex>
class test_sink : public base_sink<Mutex>
{
const size_t lines_to_save = 100;
public:
size_t msg_counter()
{
@ -33,12 +35,28 @@ public:
void set_delay(std::chrono::milliseconds delay)
{
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
delay_ = delay;
}
protected:
void sink_it_(const details::log_msg &) override
// return last output without the eol
std::vector<std::string> lines()
{
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
return lines_;
}
protected:
void sink_it_(const details::log_msg &msg) override
{
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
// save the line without the eol
auto eol_len = strlen(details::os::default_eol);
if (lines_.size() < lines_to_save)
{
lines_.emplace_back(formatted.begin(), formatted.end() - eol_len);
}
msg_counter_++;
std::this_thread::sleep_for(delay_);
}
@ -47,9 +65,11 @@ protected:
{
flush_counter_++;
}
size_t msg_counter_{0};
size_t flush_counter_{0};
std::chrono::milliseconds delay_{std::chrono::milliseconds::zero()};
std::vector<std::string> lines_;
};
using test_sink_mt = test_sink<std::mutex>;