mirror of
https://github.com/gabime/spdlog.git
synced 2026-04-10 11:34:29 +08:00
Modified from_str() to perform case-insensitive comparison for all level names. This allows environment variables and SPDLOG_LEVEL_NAMES to use uppercase or mixed case level names (e.g., DEBUG, INFO, Warning) while maintaining full backward compatibility with existing lowercase names.
This commit is contained in:
@@ -176,3 +176,33 @@ TEST_CASE("restore-to-default", "[cfg]") {
|
||||
load_argv_levels(2, argv);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
}
|
||||
|
||||
TEST_CASE("uppercase-level-names", "[cfg]") {
|
||||
spdlog::drop("l1");
|
||||
spdlog::drop("l2");
|
||||
|
||||
#ifdef CATCH_PLATFORM_WINDOWS
|
||||
_putenv_s("SPDLOG_LEVEL", "l1=DEBUG,INFO");
|
||||
#else
|
||||
setenv("SPDLOG_LEVEL", "l1=DEBUG,INFO", 1);
|
||||
#endif
|
||||
load_env_levels();
|
||||
auto l1 = spdlog::create<test_sink_st>("l1");
|
||||
auto l2 = spdlog::create<test_sink_st>("l2");
|
||||
|
||||
REQUIRE(l1->level() == spdlog::level::debug);
|
||||
REQUIRE(l2->level() == spdlog::level::info);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
|
||||
// Test with argv
|
||||
spdlog::drop("l3");
|
||||
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l3=WARN,ERROR"};
|
||||
load_argv_levels(2, argv);
|
||||
auto l3 = spdlog::create<test_sink_st>("l3");
|
||||
|
||||
REQUIRE(l3->level() == spdlog::level::warn);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err);
|
||||
|
||||
// Reset to info
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user