mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
Fixed wincolor sink
This commit is contained in:
@@ -76,7 +76,7 @@ private:
|
||||
FILE *target_file_;
|
||||
bool should_do_colors_;
|
||||
std::array<std::string, levels_count> colors_;
|
||||
void print_ccode_(const string_view_t &color_code);
|
||||
void print_ccode_(const string_view_t color_code);
|
||||
void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
|
||||
static std::string to_string_(const string_view_t sv);
|
||||
};
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "../common.h"
|
||||
#include "../details/null_mutex.h"
|
||||
#include "sink.h"
|
||||
#include "base_sink.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
@@ -19,8 +19,8 @@ namespace sinks {
|
||||
* Windows color console sink. Uses WriteConsoleA to write to the console with
|
||||
* colors
|
||||
*/
|
||||
template <typename ConsoleMutex>
|
||||
class wincolor_sink : public sink {
|
||||
template <typename Mutex>
|
||||
class wincolor_sink : public base_sink<Mutex> {
|
||||
public:
|
||||
wincolor_sink(void *out_handle, color_mode mode);
|
||||
~wincolor_sink() override;
|
||||
@@ -29,24 +29,20 @@ public:
|
||||
wincolor_sink &operator=(const wincolor_sink &other) = delete;
|
||||
|
||||
// change the color for the given level
|
||||
void set_color(level level, std::uint16_t color);
|
||||
void log(const details::log_msg &msg) final override;
|
||||
void flush() final override;
|
||||
void set_pattern(const std::string &pattern) override final;
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override final;
|
||||
void set_color(level level, std::uint16_t color);
|
||||
void set_color_mode(color_mode mode);
|
||||
|
||||
protected:
|
||||
using mutex_t = typename ConsoleMutex::mutex_t;
|
||||
void *out_handle_;
|
||||
mutex_t &mutex_;
|
||||
bool should_do_colors_;
|
||||
std::unique_ptr<spdlog::formatter> formatter_;
|
||||
private:
|
||||
void *out_handle_;
|
||||
bool should_do_colors_;
|
||||
std::array<std::uint16_t, levels_count> colors_;
|
||||
|
||||
// set foreground color and return the orig console attributes (for resetting later)
|
||||
std::uint16_t set_foreground_color_(std::uint16_t attribs);
|
||||
|
||||
void sink_it_(const details::log_msg &msg) override;
|
||||
void flush_() override;
|
||||
|
||||
// print a range of formatted message to console
|
||||
void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
|
||||
|
||||
@@ -56,22 +52,22 @@ protected:
|
||||
void set_color_mode_impl(color_mode mode);
|
||||
};
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
class wincolor_stdout_sink : public wincolor_sink<ConsoleMutex> {
|
||||
template <typename Mutex>
|
||||
class wincolor_stdout_sink : public wincolor_sink<Mutex> {
|
||||
public:
|
||||
explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic);
|
||||
};
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
class wincolor_stderr_sink : public wincolor_sink<ConsoleMutex> {
|
||||
template <typename Mutex>
|
||||
class wincolor_stderr_sink : public wincolor_sink<Mutex> {
|
||||
public:
|
||||
explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic);
|
||||
};
|
||||
|
||||
using wincolor_stdout_sink_mt = wincolor_stdout_sink<details::console_mutex>;
|
||||
using wincolor_stdout_sink_st = wincolor_stdout_sink<details::console_nullmutex>;
|
||||
using wincolor_stdout_sink_mt = wincolor_stdout_sink<std::mutex>;
|
||||
using wincolor_stdout_sink_st = wincolor_stdout_sink<details::null_mutex>;
|
||||
|
||||
using wincolor_stderr_sink_mt = wincolor_stderr_sink<details::console_mutex>;
|
||||
using wincolor_stderr_sink_st = wincolor_stderr_sink<details::console_nullmutex>;
|
||||
using wincolor_stderr_sink_mt = wincolor_stderr_sink<std::mutex>;
|
||||
using wincolor_stderr_sink_st = wincolor_stderr_sink<details::null_mutex>;
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
Reference in New Issue
Block a user