log level

This commit is contained in:
SimoneN64
2023-06-09 14:12:05 +02:00
parent 446be92d49
commit e58b867dfe

View File

@@ -4,33 +4,37 @@
#include <fmt/color.h> #include <fmt/color.h>
namespace Util { namespace Util {
enum MessageType : u8 { enum LogLevel : u8 {
Info, Debug, Warn, Error Trace, Info, Debug, Warn, Error
}; };
template <MessageType messageType = Info, typename ...Args> static constexpr auto globalLogLevel = Warn;
template <LogLevel messageType = Info, typename ...Args>
constexpr void print(const std::string& fmt, Args... args) { constexpr void print(const std::string& fmt, Args... args) {
if constexpr(messageType >= globalLogLevel) {
#ifndef _WIN32 #ifndef _WIN32
if constexpr(messageType == Error) { if constexpr(messageType == Error) {
fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt, args...); fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt, args...);
} else if constexpr(messageType == Warn) { } else if constexpr(messageType == Warn) {
fmt::print(fg(fmt::color::yellow), fmt, args...); fmt::print(fg(fmt::color::yellow), fmt, args...);
} else if constexpr(messageType == Info) { } else if constexpr(messageType == Info) {
fmt::print(fmt, args...); fmt::print(fmt, args...);
} else if constexpr(messageType == Debug) { } else if constexpr(messageType == Debug) {
#ifndef NDEBUG #ifndef NDEBUG
fmt::print(fmt, args...); fmt::print(fmt, args...);
#endif #endif
} }
#else #else
if constexpr(messageType == Debug) { if constexpr(messageType == Debug) {
#ifndef NDEBUG #ifndef NDEBUG
fmt::print(fmt, args...); fmt::print(fmt, args...);
#endif
} else {
fmt::print(fmt, args...);
}
#endif #endif
} else {
fmt::print(fmt, args...);
} }
#endif
} }
template <typename ...Args> template <typename ...Args>