From e58b867dfe282b72b3d249acc3acdfe46e9236bc Mon Sep 17 00:00:00 2001 From: SimoneN64 Date: Fri, 9 Jun 2023 14:12:05 +0200 Subject: [PATCH] log level --- src/utils/log.hpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/utils/log.hpp b/src/utils/log.hpp index 851ea748..0b681246 100644 --- a/src/utils/log.hpp +++ b/src/utils/log.hpp @@ -4,33 +4,37 @@ #include namespace Util { -enum MessageType : u8 { - Info, Debug, Warn, Error +enum LogLevel : u8 { + Trace, Info, Debug, Warn, Error }; -template +static constexpr auto globalLogLevel = Warn; + +template constexpr void print(const std::string& fmt, Args... args) { + if constexpr(messageType >= globalLogLevel) { #ifndef _WIN32 - if constexpr(messageType == Error) { - fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt, args...); - } else if constexpr(messageType == Warn) { - fmt::print(fg(fmt::color::yellow), fmt, args...); - } else if constexpr(messageType == Info) { - fmt::print(fmt, args...); - } else if constexpr(messageType == Debug) { + if constexpr(messageType == Error) { + fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt, args...); + } else if constexpr(messageType == Warn) { + fmt::print(fg(fmt::color::yellow), fmt, args...); + } else if constexpr(messageType == Info) { + fmt::print(fmt, args...); + } else if constexpr(messageType == Debug) { #ifndef NDEBUG - fmt::print(fmt, args...); + fmt::print(fmt, args...); #endif - } + } #else - if constexpr(messageType == Debug) { + if constexpr(messageType == Debug) { #ifndef NDEBUG - fmt::print(fmt, args...); + fmt::print(fmt, args...); +#endif + } else { + fmt::print(fmt, args...); + } #endif - } else { - fmt::print(fmt, args...); } -#endif } template