diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 14d5d149..56fc952d 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -85,6 +85,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]; @@ -94,6 +107,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 8c096150..fb4f4560 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -483,7 +483,7 @@ class full_formatter SPDLOG_FINAL: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()); } };