9 #include "../details/os.h" 10 #include "base_sink.h" 13 #include <unordered_map> 30 should_do_colors_ = details::os::in_terminal(file) && details::os::is_color_terminal();
31 colors_[level::trace] = white;
32 colors_[level::debug] = cyan;
33 colors_[level::info] = green;
34 colors_[level::warn] = yellow + bold;
35 colors_[level::err] = red + bold;
36 colors_[level::critical] = bold + on_red;
37 colors_[level::off] =
reset;
45 void set_color(level::level_enum color_level,
const std::string &color)
48 colors_[color_level] = color;
52 const std::string
reset =
"\033[m";
53 const std::string bold =
"\033[1m";
54 const std::string dark =
"\033[2m";
55 const std::string underline =
"\033[4m";
56 const std::string blink =
"\033[5m";
57 const std::string reverse =
"\033[7m";
58 const std::string concealed =
"\033[8m";
59 const std::string clear_line =
"\033[K";
62 const std::string black =
"\033[30m";
63 const std::string red =
"\033[31m";
64 const std::string green =
"\033[32m";
65 const std::string yellow =
"\033[33m";
66 const std::string blue =
"\033[34m";
67 const std::string magenta =
"\033[35m";
68 const std::string cyan =
"\033[36m";
69 const std::string white =
"\033[37m";
73 const std::string on_red =
"\033[41m";
74 const std::string on_green =
"\033[42m";
75 const std::string on_yellow =
"\033[43m";
76 const std::string on_blue =
"\033[44m";
77 const std::string on_magenta =
"\033[45m";
78 const std::string on_cyan =
"\033[46m";
79 const std::string on_white =
"\033[47m";
86 if (should_do_colors_ && msg.color_range_end > msg.color_range_start)
89 _print_range(msg, 0, msg.color_range_start);
91 _print_ccode(colors_[msg.level]);
92 _print_range(msg, msg.color_range_start, msg.color_range_end);
95 _print_range(msg, msg.color_range_end, msg.formatted.
size());
99 _print_range(msg, 0, msg.formatted.
size());
104 void _flush()
override 106 fflush(target_file_);
110 void _print_ccode(
const std::string &color_code)
112 fwrite(color_code.data(),
sizeof(char), color_code.size(), target_file_);
116 fwrite(msg.formatted.
data() + start,
sizeof(char), end - start, target_file_);
119 bool should_do_colors_;
120 std::unordered_map<level::level_enum, std::string, level::level_hasher> colors_;
123 template<
class Mutex>
136 template<
class Mutex>
const std::string reset
Formatting codes.
Definition: ansicolor_sink.h:52
const Char * data() const FMT_NOEXCEPT
Definition: format.h:3280
Definition: ansicolor_sink.h:137
Definition: async_logger.h:26
std::size_t size() const
Definition: format.h:3271
Definition: ansicolor_sink.h:124
Definition: ansicolor_sink.h:24
const std::string on_black
Background colors.
Definition: ansicolor_sink.h:72
Definition: base_sink.h:23