aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util/log.cpp
diff options
context:
space:
mode:
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