From ae82a980756c9d95cc4c98bd3559081fdf33d6e0 Mon Sep 17 00:00:00 2001 From: Alexander Danilov Date: Tue, 16 Aug 2016 11:46:26 +0300 Subject: [PATCH] level color --- include/spdlog/common.h | 18 ++++++++++++++++++ .../spdlog/details/pattern_formatter_impl.h | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 490deec7..b39683ca 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -80,6 +80,19 @@ static const char* level_names[] { "trace", "debug", "info", "warning", "error" static const char* short_level_names[] { "T", "D", "I", "W", "E", "C", "O" }; +static const char* level_color[] { + "\e[34m", // trace -> Blue + "\e[34m", // debug -> Blue + "\e[96m", // info -> Light cyan + "\e[96m", // notice -> Light cyan + "\e[43m", // warning -> Yellow + "\e[91m", // error -> Light red + "\e[91m", // critical -> Light red + "\e[91m", // alert -> Light red + "\e[91m", // emerg -> Light red + "" +}; + inline const char* to_str(spdlog::level::level_enum l) { return level_names[l]; @@ -89,6 +102,11 @@ inline const char* to_short_str(spdlog::level::level_enum l) { return short_level_names[l]; } + +inline const char* get_color(spdlog::level::level_enum l) +{ + return level_color[l]; +} } //level diff --git a/include/spdlog/details/pattern_formatter_impl.h b/include/spdlog/details/pattern_formatter_impl.h index 663a2558..39bc7b1e 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -440,7 +440,7 @@ class full_formatter:public flag_formatter msg.formatted << '[' << *msg.logger_name << "] "; #endif - msg.formatted << '[' << level::to_str(msg.level) << "] "; + msg.formatted << '[' << level::get_color(msg.level) << level::to_str(msg.level) << "\e[0m" << "] "; msg.formatted << fmt::StringRef(msg.raw.data(), msg.raw.size()); } };