I need to turn off the spdlog level before some code then return it to the previous value after.
How do I get the current level before turning it off?
To get current level of logger use logger::level() .
To set new level use logger::set_level() .
If you have a spdlog::logger
object you're using (say, my_logger
), then:
my_logger.level()
.my_logger.should_log(some_level)
where some_level
could be, for example spdlog::level::debug
.Now suppose you're using the global logger (eg you emit log messages using spdlog::info()
, spdlog::error()
and such).
spdlog
version 1.8.0 and later
You can obtain the global log level with a call to spdlog::get_level()
(which is a freestanding function, not a method).
spdlog
versions before 1.8.0
You need to get your hand on the implicit logger object - by calling spdlog::default_logger_raw()
(it gets you a pointer.) Now just proceed as in Scenario 1 above.
现在似乎有一个获取全局日志级别的函数:
spdlog::get_level();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.