diff options
| author | thejch <66577496+thejch@users.noreply.github.com> | 2024-04-29 08:07:35 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-29 16:07:35 +0100 |
| commit | a783cd8f40594b686bc40d52a2af95bedba7a8d5 (patch) | |
| tree | e5740d406d61051375de53e17cef731f67f1c80e /src/debug | |
| parent | 33e0bb14786dc22a0c82eaaf097b469d3fdeceea (diff) | |
log: Add some colors to stdout log 🔴🟡🟢🔵🟣 (#5778)
* add colored log
* add config option
* make it dynamic
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/Log.cpp | 35 | ||||
| -rw-r--r-- | src/debug/Log.hpp | 1 |
2 files changed, 28 insertions, 8 deletions
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"; +} diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp index f1dd3eab..abf74065 100644 --- a/src/debug/Log.hpp +++ b/src/debug/Log.hpp @@ -27,6 +27,7 @@ namespace Debug { inline bool disableStdout = false; inline bool trace = false; inline bool shuttingDown = false; + inline int64_t* const* coloredLogs = nullptr; inline std::string rollingLog = ""; // rolling log contains the ROLLING_LOG_SIZE tail of the log |
