Files
kaizen/external/ircolib/log.hpp
T

62 lines
1.7 KiB
C++

#pragma once
#include <print>
#include <ircolib/types.hpp>
namespace ircolib {
enum LogLevel : u8 { Trace, Debug, Info, Warn, Error, Always };
constexpr LogLevel globalLogLevel = Warn;
template <typename... Args>
void panic(std::format_string<Args...> fmt, Args &&...args) {
std::print("[FATAL] ");
std::println(fmt, std::forward<Args>(args)...);
exit(1);
}
template <typename... Args>
void error(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Error >= globalLogLevel) {
std::print("[ERROR] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void warn(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Warn >= globalLogLevel) {
std::print("[WARN] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void info(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Info >= globalLogLevel) {
std::print("[INFO] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void debug(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Debug >= globalLogLevel) {
std::print("[DEBUG] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void trace(std::format_string<Args...> fmt, Args &&...args) {
if (LogLevel::Trace >= globalLogLevel) {
std::print("[TRACE] ");
std::println(fmt, std::forward<Args>(args)...);
}
}
template <typename... Args>
void always(std::format_string<Args...> fmt, Args &&...args) {
std::println(fmt, std::forward<Args>(args)...);
}
} // namespace ircolib