diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-07 17:55:15 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-07 18:03:03 +0800 |
| commit | 3972c5f76483bf5f64bcf19685ee391c4d6b1a9b (patch) | |
| tree | db258338afafa632d3f51baed3665c3c1f1dbb05 /src/log.hpp | |
| parent | c37bd3e34f5840773949bb55848cda3af6688d20 (diff) | |
refactor(format,log): better/simpler way to do them
Diffstat (limited to 'src/log.hpp')
| -rw-r--r-- | src/log.hpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/log.hpp b/src/log.hpp index a6c6ea2..8cfc917 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -1,28 +1,23 @@ #pragma once #include "format.hpp" -#include <chrono> #include <format> #include <print> #include <string> -enum eLogLevel : int8_t { - INFO = 0, - WARN, - ERROR, - FATAL -}; - -inline bool useColors = true; +inline void log(FILE* _stream, eFormatType type, std::string str) { + std::println(_stream, "{}", NFormatter::fmt(type, str)); +} -void log(eLogLevel level, std::string str); +inline void log(eFormatType type, std::string str) { + log(stdout, type, 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)...); +void log(FILE* _stream, eFormatType type, std::format_string<Args...> fmt, Args &&...args) { + log(_stream, type, std::format(fmt, std::forward<Args>(args)...)); +} - log(level, timeStamp + msg); +template <typename... Args> +void log(eFormatType type, std::format_string<Args...> fmt, Args &&...args) { + log(stdout, type, std::format(fmt, std::forward<Args>(args)...)); } |
