summaryrefslogtreecommitdiff
path: root/src/log.hpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-05 23:44:56 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-03-07 18:03:03 +0800
commitc37bd3e34f5840773949bb55848cda3af6688d20 (patch)
tree1d31ea7c3cf8811ea294da9c094027a9e805dfcb /src/log.hpp
parentaa21e4ea0687fd0c8d333161f5ec31a580512e9e (diff)
refactor: logging system
Diffstat (limited to 'src/log.hpp')
-rw-r--r--src/log.hpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/log.hpp b/src/log.hpp
index 1ee401e..a6c6ea2 100644
--- a/src/log.hpp
+++ b/src/log.hpp
@@ -1,12 +1,28 @@
#pragma once
-
-#include <map>
+#include "format.hpp"
+#include <chrono>
+#include <format>
+#include <print>
#include <string>
-typedef enum {
- LOG_LEVEL_DEBUG = 0,
- LOG_LEVEL_INFO,
- LOG_LEVEL_WARN,
- LOG_LEVEL_ERROR,
- LOG_LEVEL_FATAL,
- LOG_LEVEL_MAX
-} eLogLevel;
+
+enum eLogLevel : int8_t {
+ INFO = 0,
+ WARN,
+ ERROR,
+ FATAL
+};
+
+inline bool useColors = true;
+
+void log(eLogLevel level, std::string str);
+
+template <typename... Args>
+void log(eLogLevel level, std::format_string<Args...> fmt, Args &&...args) {
+ const auto now = std::chrono::system_clock::now();
+ const auto hms = std::chrono::hh_mm_ss{now - std::chrono::floor<std::chrono::days>(now)};
+ std::string timeStamp = std::format("[{}] ", hms);
+
+ std::string msg = CFormatter::fmt(eFormatType::RAW, fmt, std::forward<Args>(args)...);
+
+ log(level, timeStamp + msg);
+}