From e842f12e0b6319c7b43cd8e13d3f825b8ba34a55 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Mon, 16 Dec 2024 17:46:38 +0000 Subject: [PATCH] Add level setter --- logger.hpp.in | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/logger.hpp.in b/logger.hpp.in index 3de2e32..d8d3cd9 100644 --- a/logger.hpp.in +++ b/logger.hpp.in @@ -481,6 +481,24 @@ inline logger& default_logger() return logger_; } +/** + * @brief An object used for scoped log level setting + * + * Instances will set the logging to the level indicated on construction and + * will revert to the previous set level on destruction. + */ +struct log_level_setter { + explicit log_level_setter(level_enum level) + { + prev_level_ = default_logger().level(); + default_logger().set_level(level); + } + ~log_level_setter() { default_logger().set_level(prev_level_); } + + private: + level_enum prev_level_; +}; + // Macros for easier logging, similar to spdlog. #if !defined(@_RAPIDS_LOGGER_MACRO_PREFIX@_LOG_ACTIVE_LEVEL) #define @_RAPIDS_LOGGER_MACRO_PREFIX@_LOG_ACTIVE_LEVEL @_RAPIDS_LOGGER_MACRO_PREFIX@_LOG_LEVEL_INFO