Class wincolor_sink

Synopsis

#include <include/spdlog/sinks/wincolor_sink.h>

template<typename ConsoleMutex>
class wincolor_sink : public sink

Description

Windows color console sink. Uses WriteConsoleA to write to the console with colors

Inheritance

Ancestors: sink

Decsendents: wincolor_stdout_sink, wincolor_stderr_sink

Methods

wincolor_sink overload
~wincolor_sink
flush
log
operator=
set_colorchange the color for the given level
set_color_mode
set_color_mode_impl
set_foreground_color_set foreground color and return the orig console attributes (for resetting later)
set_formatter
set_pattern
write_to_file_in case we are redirected to file (not in console mode)

Source

Lines 23-59 in include/spdlog/sinks/wincolor_sink.h.

template<typename ConsoleMutex>
class wincolor_sink : public sink
{
public:   
    wincolor_sink(void *out_handle, color_mode mode);
    ~wincolor_sink() override;

    wincolor_sink(const wincolor_sink &other) = delete;
    wincolor_sink &operator=(const wincolor_sink &other) = delete;

    // change the color for the given level
    void set_color(level::level_enum 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_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_;
    std::array<std::uint16_t, level::n_levels> colors_;

    // set foreground color and return the orig console attributes (for resetting later)
    std::uint16_t set_foreground_color_(std::uint16_t attribs);

    // print a range of formatted message to console
    void print_range_(const memory_buf_t &formatted, size_t start, size_t end);

    // in case we are redirected to file (not in console mode)
    void write_to_file_(const memory_buf_t &formatted);

    void set_color_mode_impl(color_mode mode);
};





Add Discussion

Log in to comment