summaryrefslogtreecommitdiff
path: root/src/log.hpp
diff options
context:
space:
mode:
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);
+}