add loglevel commands
This commit is contained in:
22
logging.hpp
22
logging.hpp
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user