TeaSpeakLibrary/src/log/LogSinks.h

38 lines
1.2 KiB
C
Raw Permalink Normal View History

2019-06-26 16:11:22 -04:00
#pragma once
#include <spdlog/logger.h>
2019-11-23 15:16:55 -05:00
#include <spdlog/sinks/base_sink.h>
2019-06-26 16:11:22 -04:00
namespace logger {
2020-01-23 20:49:59 -05:00
class ColorCodeFormatter : public spdlog::formatter {
public:
void format(const spdlog::details::log_msg &msg, spdlog::memory_buf_t &dest) override {
dest.append(msg.payload.begin(), msg.payload.end());
}
2019-11-23 15:16:55 -05:00
2020-01-23 20:49:59 -05:00
[[nodiscard]] std::unique_ptr<formatter> clone() const override {
return std::unique_ptr<ColorCodeFormatter>();
}
};
2019-11-23 15:16:55 -05:00
//TODO: Mutex really needed here?
2020-01-23 20:49:59 -05:00
class TerminalSink : public spdlog::sinks::base_sink<std::mutex> {
2019-06-26 16:11:22 -04:00
public:
2020-01-23 20:49:59 -05:00
void sink_it_(const spdlog::details::log_msg &msg) override;
void flush_() override;
2019-06-26 16:11:22 -04:00
};
2020-01-23 20:49:59 -05:00
class LogFormatter : public spdlog::formatter {
public:
explicit LogFormatter(bool colored) : _colored{colored} {}
2019-06-26 16:11:22 -04:00
2020-01-23 20:49:59 -05:00
void format(const spdlog::details::log_msg &msg, spdlog::memory_buf_t &dest) override;
[[nodiscard]] std::unique_ptr<formatter> clone() const override;
2019-06-26 16:11:22 -04:00
2020-01-23 20:49:59 -05:00
inline bool colored() const { return this->_colored; }
inline void colored(bool flag) { this->_colored = flag; }
private:
bool _colored{true};
};
2019-06-26 16:11:22 -04:00
}