aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util/log.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-21 11:17:23 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-21 11:17:23 +0200
commite58c98e224afcf4a28078344e0cd5f8c0e10961f (patch)
treed165add07884e842321a6b7af85ee47c1b07355e /src/crepe/util/log.cpp
parent157cdabe941be14ca72022e7a7c8c55a582a7c1c (diff)
add logging example + finish log color config integration
Diffstat (limited to 'src/crepe/util/log.cpp')
-rw-r--r--src/crepe/util/log.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp
index e3e9f1f..a2672a3 100644
--- a/src/crepe/util/log.cpp
+++ b/src/crepe/util/log.cpp
@@ -8,21 +8,24 @@
#include "../api/Config.h"
using namespace crepe::util;
+using namespace std;
+
+string log_prefix(log_level level) {
+ switch (level) {
+ case log_level::TRACE: return LogColor().fg_white().str("[TRACE]") + " ";
+ case log_level::DEBUG: return LogColor().fg_magenta().str("[DEBUG]") + " ";
+ case log_level::INFO: return LogColor().fg_blue().str("[INFO]") + " ";
+ case log_level::WARNING: return LogColor().fg_yellow().str("[WARN]") + " ";
+ case log_level::ERROR: return LogColor().fg_red().str("[ERROR]") + " ";
+ }
+ return "";
+}
-static const char * const LOG_PREFIX[] = {
- [log_level::TRACE] = "[TRACE] ",
- [log_level::DEBUG] = "[DEBUG] ",
- [log_level::INFO] = "[INFO] ",
- [log_level::WARNING] = "[WARN] ",
- [log_level::ERROR] = "[ERROR] ",
-};
-
-static void log(enum log_level level, const std::string msg) {
+static void log(enum log_level level, const string msg) {
auto & cfg = crepe::api::Config::get_instance();
if (level < cfg.log.level) return;
- using namespace std;
- string final = string(LOG_PREFIX[level]) + msg;
+ string final = log_prefix(level) + msg;
if (!final.ends_with("\n")) final += "\n";
// TODO: also log to file or smth