From 3972c5f76483bf5f64bcf19685ee391c4d6b1a9b Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 7 Mar 2025 17:55:15 +0800 Subject: refactor(format,log): better/simpler way to do them --- src/log.hpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/log.hpp') 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 #include #include #include -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 -void log(eLogLevel level, std::format_string fmt, Args &&...args) { - const auto now = std::chrono::system_clock::now(); - const auto hms = std::chrono::hh_mm_ss{now - std::chrono::floor(now)}; - std::string timeStamp = std::format("[{}] ", hms); - - std::string msg = CFormatter::fmt(eFormatType::RAW, fmt, std::forward(args)...); +void log(FILE* _stream, eFormatType type, std::format_string fmt, Args &&...args) { + log(_stream, type, std::format(fmt, std::forward(args)...)); +} - log(level, timeStamp + msg); +template +void log(eFormatType type, std::format_string fmt, Args &&...args) { + log(stdout, type, std::format(fmt, std::forward(args)...)); } -- cgit v1.2.3