Update ansicolor_sink.h

pull/690/head
Bousk 8 years ago committed by GitHub
parent 91cd92f80e
commit 9600ffd47f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,9 +31,9 @@ public:
colors_[level::trace] = cyan;
colors_[level::debug] = cyan;
colors_[level::info] = reset;
colors_[level::warn] = yellow + bold;
colors_[level::err] = red + bold;
colors_[level::critical] = bold + on_red;
colors_[level::warn] = string(yellow) + bold;
colors_[level::err] = string(red) + bold;
colors_[level::critical] = string(bold) + on_red;
colors_[level::off] = reset;
}
@ -42,41 +42,41 @@ public:
_flush();
}
void set_color(level::level_enum color_level, const std::string &color)
void set_color(level::level_enum color_level, const string &color)
{
std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex);
colors_[color_level] = color;
}
/// Formatting codes
const std::string reset = "\033[m";
const std::string bold = "\033[1m";
const std::string dark = "\033[2m";
const std::string underline = "\033[4m";
const std::string blink = "\033[5m";
const std::string reverse = "\033[7m";
const std::string concealed = "\033[8m";
const std::string clear_line = "\033[K";
const char* reset = "\033[m";
const char* bold = "\033[1m";
const char* dark = "\033[2m";
const char* underline = "\033[4m";
const char* blink = "\033[5m";
const char* reverse = "\033[7m";
const char* concealed = "\033[8m";
const char* clear_line = "\033[K";
// Foreground colors
const std::string black = "\033[30m";
const std::string red = "\033[31m";
const std::string green = "\033[32m";
const std::string yellow = "\033[33m";
const std::string blue = "\033[34m";
const std::string magenta = "\033[35m";
const std::string cyan = "\033[36m";
const std::string white = "\033[37m";
const char* black = "\033[30m";
const char* red = "\033[31m";
const char* green = "\033[32m";
const char* yellow = "\033[33m";
const char* blue = "\033[34m";
const char* magenta = "\033[35m";
const char* cyan = "\033[36m";
const char* white = "\033[37m";
/// Background colors
const std::string on_black = "\033[40m";
const std::string on_red = "\033[41m";
const std::string on_green = "\033[42m";
const std::string on_yellow = "\033[43m";
const std::string on_blue = "\033[44m";
const std::string on_magenta = "\033[45m";
const std::string on_cyan = "\033[46m";
const std::string on_white = "\033[47m";
const char* on_black = "\033[40m";
const char* on_red = "\033[41m";
const char* on_green = "\033[42m";
const char* on_yellow = "\033[43m";
const char* on_blue = "\033[44m";
const char* on_magenta = "\033[45m";
const char* on_cyan = "\033[46m";
const char* on_white = "\033[47m";
protected:
void _sink_it(const details::log_msg &msg) override
@ -85,7 +85,7 @@ protected:
// If color is not supported in the terminal, log as is instead.
if (should_do_colors_)
{
const std::string &prefix = colors_[msg.level];
const string& prefix = colors_[msg.level];
fwrite(prefix.data(), sizeof(char), prefix.size(), target_file_);
fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), target_file_);
fwrite(reset.data(), sizeof(char), reset.size(), target_file_);
@ -105,7 +105,7 @@ protected:
FILE *target_file_;
bool should_do_colors_;
std::unordered_map<level::level_enum, std::string, level::level_hasher> colors_;
unordered_map<level::level_enum, string, level::level_hasher> colors_;
};
template<class Mutex>

Loading…
Cancel
Save