20 #include <unordered_map> 31 template<
typename TargetStream,
class ConsoleMutex>
35 using mutex_t =
typename ConsoleMutex::mutex_t;
37 : target_file_(TargetStream::stream())
38 , mutex_(ConsoleMutex::mutex())
58 std::lock_guard<mutex_t> lock(mutex_);
59 colors_[color_level] =
color;
63 const std::string
reset =
"\033[m";
64 const std::string
bold =
"\033[1m";
65 const std::string
dark =
"\033[2m";
67 const std::string
blink =
"\033[5m";
73 const std::string
black =
"\033[30m";
74 const std::string
red =
"\033[31m";
75 const std::string
green =
"\033[32m";
76 const std::string
yellow =
"\033[33m";
77 const std::string
blue =
"\033[34m";
79 const std::string
cyan =
"\033[36m";
80 const std::string
white =
"\033[37m";
84 const std::string
on_red =
"\033[41m";
96 std::lock_guard<mutex_t> lock(mutex_);
105 print_ccode_(colors_[msg.
level]);
113 print_range_(formatted, 0, formatted.
size());
115 fflush(target_file_);
120 std::lock_guard<mutex_t> lock(mutex_);
121 fflush(target_file_);
126 std::lock_guard<mutex_t> lock(mutex_);
130 void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
override 132 std::lock_guard<mutex_t> lock(mutex_);
138 return should_do_colors_;
142 void print_ccode_(
const std::string &color_code)
144 fwrite(color_code.data(),
sizeof(char), color_code.size(), target_file_);
148 fwrite(formatted.
data() + start,
sizeof(char), end - start, target_file_);
154 bool should_do_colors_;
155 std::unordered_map<level::level_enum, std::string, level::level_hasher> colors_;
const std::string on_yellow
const std::string reverse
const std::string on_black
Background colors.
~ansicolor_sink() override=default
const std::string reset
Formatting codes.
const std::string underline
std::unique_ptr< spdlog::formatter > formatter_
const std::string magenta
bool is_color_terminal() noexcept
const std::string on_white
const std::string on_blue
const std::string concealed
bool in_terminal(FILE *file) noexcept
const std::string on_cyan
void set_pattern(const std::string &pattern) final
typename ConsoleMutex::mutex_t mutex_t
const std::string clear_line
void log(const details::log_msg &msg) override
void set_color(level::level_enum color_level, const std::string &color)
void set_formatter(std::unique_ptr< spdlog::formatter > sink_formatter) override
const std::string on_magenta
const std::string on_green
auto end(const C &c) -> decltype(c.end())
ansicolor_sink & operator=(const ansicolor_sink &other)=delete