Added a test for level enforcement
This commit is contained in:
parent
d77b23c719
commit
ea49998a6e
@ -220,3 +220,23 @@ TEST_CASE("default logger API", "[default logger]")
|
||||
spdlog::drop_all();
|
||||
spdlog::set_pattern("%v");
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("enforce level", "[enforce logging]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
|
||||
spdlog::set_default_logger(std::make_shared<spdlog::logger>("oss", oss_sink));
|
||||
spdlog::set_pattern("*** %v");
|
||||
|
||||
spdlog::default_logger()->set_level(spdlog::level::critical);
|
||||
spdlog::default_logger()->log(spdlog::source_loc{}, spdlog::level::forceable{spdlog::level::info, false}, "should not be logged");
|
||||
REQUIRE(oss.str().empty());
|
||||
|
||||
spdlog::default_logger()->log(spdlog::source_loc{}, spdlog::level::forceable{spdlog::level::info, true}, "should be logged");
|
||||
REQUIRE(oss.str() == "*** should be logged");
|
||||
|
||||
spdlog::drop_all();
|
||||
spdlog::set_pattern("%v");
|
||||
}
|
Loading…
Reference in New Issue
Block a user