mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-13 10:42:56 +01:00
restore needs a flag to remove custom levels (at least the tests need to be able to do it)
addLogLevel again resets the log level to the passed enable_state as even requesting the level before adding it would otherwise lead to unexpectedly not setting a "new" level to the passed state. We now assume setLogLevel is not called before addLogLevel without considering this behavior.
This commit is contained in:
parent
a98b91fc5c
commit
7d1481724c
@ -115,9 +115,9 @@ namespace g3 {
|
||||
namespace only_change_at_initialization {
|
||||
// Enable/Disable a log level {DEBUG,INFO,WARNING,FATAL}
|
||||
void setLogLevel(LEVELS level, bool enabled_status);
|
||||
void addLogLevel(LEVELS level, bool default_enabled_status = true);
|
||||
void addLogLevel(LEVELS level, bool enabled_status = true);
|
||||
std::string printLevels();
|
||||
void reset();
|
||||
void reset(bool remove_custom_levels = false);
|
||||
|
||||
} // only_change_at_initialization
|
||||
#endif
|
||||
|
@ -52,10 +52,9 @@ namespace g3 {
|
||||
internal::g_log_level_status[level].get().store(enabled_status, std::memory_order_release);
|
||||
}
|
||||
|
||||
void addLogLevel(LEVELS log_level, bool default_enabled_status) {
|
||||
internal::g_default_log_level_status[log_level.value].get().store(default_enabled_status, std::memory_order_release);
|
||||
if (! internal::g_log_level_status.count(log_level.value))
|
||||
setLogLevel(log_level, default_enabled_status);
|
||||
void addLogLevel(LEVELS log_level, bool enabled_status) {
|
||||
internal::g_default_log_level_status[log_level.value].get().store(enabled_status, std::memory_order_release);
|
||||
setLogLevel(log_level, enabled_status);
|
||||
}
|
||||
|
||||
std::string printLevels() {
|
||||
@ -66,9 +65,10 @@ namespace g3 {
|
||||
return levels;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
internal::g_log_level_status.clear();
|
||||
internal::g_log_level_status = internal::g_default_log_level_status;
|
||||
void reset(bool remove_custom_levels) {
|
||||
if (remove_custom_levels)
|
||||
internal::g_default_log_level_status = { { g3::kDebugValue, true },{ INFO.value, true },{ WARNING.value, true },{ FATAL.value, true } };
|
||||
internal::g_log_level_status = internal::g_default_log_level_status;
|
||||
}
|
||||
} // only_change_at_initialization
|
||||
#endif
|
||||
|
@ -572,7 +572,7 @@ namespace {
|
||||
RestoreDynamicLoggingLevels() {
|
||||
};
|
||||
~RestoreDynamicLoggingLevels() {
|
||||
g3::only_change_at_initialization::reset();
|
||||
g3::only_change_at_initialization::reset(true);
|
||||
g3::only_change_at_initialization::setLogLevel(DEBUG, false);
|
||||
g3::only_change_at_initialization::setLogLevel(INFO, false);
|
||||
g3::only_change_at_initialization::setLogLevel(WARNING, false);
|
||||
@ -592,6 +592,16 @@ TEST(CustomLogLevels, AddANonFatal__ThenReset) {
|
||||
EXPECT_FALSE(g3::logLevel(MYINFO));
|
||||
}
|
||||
|
||||
TEST(CustomLogLevels, AddANonFatalWithDefault__ThenReset) {
|
||||
RestoreFileLogger logger(log_directory);
|
||||
RestoreDynamicLoggingLevels raiiLevelRestore;
|
||||
const LEVELS MYINFO{ WARNING.value + 2,{ "MY_INFO_LEVEL" } };
|
||||
EXPECT_FALSE(g3::logLevel(MYINFO));
|
||||
g3::only_change_at_initialization::addLogLevel(MYINFO, true);
|
||||
EXPECT_TRUE(g3::logLevel(MYINFO));
|
||||
g3::only_change_at_initialization::reset();
|
||||
EXPECT_TRUE(g3::logLevel(MYINFO));
|
||||
}
|
||||
|
||||
TEST(CustomLogLevels, AddANonFatal__DidNotAddItToEnabledValue1) {
|
||||
RestoreFileLogger logger(log_directory);
|
||||
|
Loading…
Reference in New Issue
Block a user