diff --git a/logging/logging.h b/logging/logging.h index 243016a0..4ffcc376 100644 --- a/logging/logging.h +++ b/logging/logging.h @@ -7,10 +7,11 @@ namespace cpputils { namespace logging { - - enum Level { - ERROR, WARN, INFO, DEBUG - }; + + extern struct ERROR_TYPE {} ERROR; + extern struct WARN_TYPE {} WARN; + extern struct INFO_TYPE {} INFO; + extern struct DEBUG_TYPE {} DEBUG; inline void setLogger(std::shared_ptr newLogger) { logger().setLogger(newLogger); @@ -20,24 +21,36 @@ namespace cpputils { logger().reset(); } - inline void setLevel(Level level) { - switch(level) { - case ERROR: logger().setLevel(spdlog::level::err); return; - case WARN: logger().setLevel(spdlog::level::warn); return; - case INFO: logger().setLevel(spdlog::level::info); return; - case DEBUG: logger().setLevel(spdlog::level::debug); return; - } - throw std::logic_error("Unknown logger level"); + inline void setLevel(ERROR_TYPE) { + logger().setLevel(spdlog::level::err); } - inline spdlog::details::line_logger LOG(Level level) { - switch(level) { - case ERROR: return logger()->error(); - case WARN: return logger()->warn(); - case INFO: return logger()->info(); - case DEBUG: return logger()->debug(); - } - throw std::logic_error("Unknown logger level"); + inline void setLevel(WARN_TYPE) { + logger().setLevel(spdlog::level::warn); + } + + inline void setLevel(INFO_TYPE) { + logger().setLevel(spdlog::level::info); + } + + inline void setLevel(DEBUG_TYPE) { + logger().setLevel(spdlog::level::debug); + } + + inline spdlog::details::line_logger LOG(ERROR_TYPE) { + return logger()->error(); + } + + inline spdlog::details::line_logger LOG(WARN_TYPE) { + return logger()->warn(); + } + + inline spdlog::details::line_logger LOG(INFO_TYPE) { + return logger()->info(); + } + + inline spdlog::details::line_logger LOG(DEBUG_TYPE) { + return logger()->debug(); } } }