add loglevel commands

This commit is contained in:
2023-02-19 22:47:24 +01:00
parent fa85779088
commit 045302cc96
2 changed files with 36 additions and 17 deletions

View File

@@ -11,7 +11,7 @@ enum class LogLevel {
TRACE,
};
inline std::string_view get_loglevel_string(LogLevel level) {
inline constexpr std::string_view get_loglevel_string(LogLevel level) {
switch (level) {
case (LogLevel::ERROR): {
return "[Error]";
@@ -61,23 +61,35 @@ class log {
template <typename... Args>
static void error(Args&&... args) {
log_impl_begin(LogLevel::ERROR);
if (!log_impl_begin(LogLevel::ERROR)) {
return;
}
log_impl(std::forward<Args&&>(args)...);
}
template <typename... Args>
static void debug(Args&&... args) {
log_impl_begin(LogLevel::DEBUG);
if (!log_impl_begin(LogLevel::DEBUG)) {
return;
}
log_impl(std::forward<Args&&>(args)...);
}
template <typename... Args>
static void info(Args&&... args) {
log_impl_begin(LogLevel::INFO);
if (!log_impl_begin(LogLevel::INFO)) {
return;
}
log_impl(std::forward<Args&&>(args)...);
}
static void set_loglevel(LogLevel level) { log_level = level; }
static void set_loglevel(LogLevel level) {
info("New LogLevel: ", get_loglevel_string(level));
log_level = level;
}
private:
static bool log_impl_begin(LogLevel level) {