From a783cd8f40594b686bc40d52a2af95bedba7a8d5 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Mon, 29 Apr 2024 08:07:35 -0700 Subject: =?UTF-8?q?log:=20Add=20some=20colors=20to=20stdout=20log=20?= =?UTF-8?q?=F0=9F=94=B4=F0=9F=9F=A1=F0=9F=9F=A2=F0=9F=94=B5=F0=9F=9F=A3=20?= =?UTF-8?q?(#5778)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add colored log * add config option * make it dynamic --- src/debug/Log.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/debug/Log.cpp') diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp index 9fdf47f8..8b82c852 100644 --- a/src/debug/Log.cpp +++ b/src/debug/Log.cpp @@ -40,13 +40,32 @@ void Debug::log(LogLevel level, std::string str) { if (shuttingDown) return; + std::string coloredStr = str; switch (level) { - case LOG: str = "[LOG] " + str; break; - case WARN: str = "[WARN] " + str; break; - case ERR: str = "[ERR] " + str; break; - case CRIT: str = "[CRITICAL] " + str; break; - case INFO: str = "[INFO] " + str; break; - case TRACE: str = "[TRACE] " + str; break; + case LOG: + str = "[LOG] " + str; + coloredStr = str; + break; + case WARN: + str = "[WARN] " + str; + coloredStr = "\033[1;33m" + str + "\033[0m"; // yellow + break; + case ERR: + str = "[ERR] " + str; + coloredStr = "\033[1;31m" + str + "\033[0m"; // red + break; + case CRIT: + str = "[CRITICAL] " + str; + coloredStr = "\033[1;35m" + str + "\033[0m"; // magenta + break; + case INFO: + str = "[INFO] " + str; + coloredStr = "\033[1;32m" + str + "\033[0m"; // green + break; + case TRACE: + str = "[TRACE] " + str; + coloredStr = "\033[1;34m" + str + "\033[0m"; // blue + break; default: break; } @@ -65,5 +84,5 @@ void Debug::log(LogLevel level, std::string str) { // log it to the stdout too. if (!disableStdout) - std::cout << str << "\n"; -} \ No newline at end of file + std::cout << ((coloredLogs && !**coloredLogs) ? str : coloredStr) << "\n"; +} -- cgit v1.2.3