diff options
author | Eric Milkie <milkie@10gen.com> | 2015-01-13 14:32:18 -0500 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2015-01-15 08:05:02 -0500 |
commit | 2238749896b7e3f7e371c75d47344ade4eb437e2 (patch) | |
tree | bbc74d8fbe7ef77a673d403de4882f53cb20d9aa /src/mongo/logger | |
parent | 8a4251527bd8112c70c72738a9beacf7067e6b48 (diff) | |
download | mongo-2238749896b7e3f7e371c75d47344ade4eb437e2.tar.gz |
SERVER-16754 correct shouldLog() to respect the current default component
Diffstat (limited to 'src/mongo/logger')
-rw-r--r-- | src/mongo/logger/component_message_log_domain.cpp | 4 | ||||
-rw-r--r-- | src/mongo/logger/component_message_log_domain.h | 1 | ||||
-rw-r--r-- | src/mongo/logger/log_component_settings.cpp | 4 | ||||
-rw-r--r-- | src/mongo/logger/log_component_settings.h | 9 | ||||
-rw-r--r-- | src/mongo/logger/log_function_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/logger/log_test.cpp | 55 |
6 files changed, 50 insertions, 31 deletions
diff --git a/src/mongo/logger/component_message_log_domain.cpp b/src/mongo/logger/component_message_log_domain.cpp index c22617e651f..3e198deb6e4 100644 --- a/src/mongo/logger/component_message_log_domain.cpp +++ b/src/mongo/logger/component_message_log_domain.cpp @@ -40,10 +40,6 @@ namespace logger { return _settings.hasMinimumLogSeverity(component); } - bool ComponentMessageLogDomain::shouldLog(LogSeverity severity) const { - return _settings.shouldLog(severity); - } - bool ComponentMessageLogDomain::shouldLog(LogComponent component, LogSeverity severity) const { return _settings.shouldLog(component, severity); } diff --git a/src/mongo/logger/component_message_log_domain.h b/src/mongo/logger/component_message_log_domain.h index 79be26380e2..4082817a276 100644 --- a/src/mongo/logger/component_message_log_domain.h +++ b/src/mongo/logger/component_message_log_domain.h @@ -47,7 +47,6 @@ namespace logger { * Predicate that answers the question, "Should I, the caller, append to you, the log * domain, messages of the given severity?" True means yes. */ - bool shouldLog(LogSeverity severity) const; bool shouldLog(LogComponent component, LogSeverity severity) const; bool shouldLog(LogComponent component1, LogComponent component2, LogSeverity severity) const; diff --git a/src/mongo/logger/log_component_settings.cpp b/src/mongo/logger/log_component_settings.cpp index 523155d64b2..825149960d8 100644 --- a/src/mongo/logger/log_component_settings.cpp +++ b/src/mongo/logger/log_component_settings.cpp @@ -90,10 +90,6 @@ namespace logger { _hasMinimumLoggedSeverity[component] = false; } - bool LogComponentSettings::shouldLog(LogSeverity severity) const { - return severity >= LogSeverity::cast(_minimumLoggedSeverity[LogComponent::kDefault]); - } - bool LogComponentSettings::shouldLog(LogComponent component, LogSeverity severity) const { dassert(int(component) >= 0 && int(component) < LogComponent::kNumLogComponents); diff --git a/src/mongo/logger/log_component_settings.h b/src/mongo/logger/log_component_settings.h index 616ae494bf9..6e27b193876 100644 --- a/src/mongo/logger/log_component_settings.h +++ b/src/mongo/logger/log_component_settings.h @@ -70,14 +70,11 @@ namespace logger { /** * Predicate that answers the question, "Should I, the caller, append to you, the log - * domain, componentged messages of the given severity?" True means yes. + * domain, componented messages of the given severity?" True means yes. * - * No components provided means to check against kDefault only. - * - * If a component is specified but minimum severity levels are not configured, - * compare 'severity' against the configured level for kDefault. + * If minimum severity levels are not configured, compare 'severity' against the configured + * level for kDefault. */ - bool shouldLog(LogSeverity severity) const; bool shouldLog(LogComponent component, LogSeverity severity) const; private: diff --git a/src/mongo/logger/log_function_test.cpp b/src/mongo/logger/log_function_test.cpp index cd34b010de9..f4ffb85752b 100644 --- a/src/mongo/logger/log_function_test.cpp +++ b/src/mongo/logger/log_function_test.cpp @@ -62,6 +62,7 @@ namespace { TEST_F(LogTestDetailsEncoder, LogFunctionsOverrideGlobalComponent) { // severe() - no component specified. severe() << "This is logged"; + ASSERT_TRUE(shouldLog(LogSeverity::Severe())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " F " << componentB.getNameForLog()), std::string::npos); @@ -69,6 +70,7 @@ namespace { // severe() - with component. _logLines.clear(); severe(componentA) << "This is logged"; + ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Severe())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " F " << componentA.getNameForLog()), std::string::npos); @@ -76,6 +78,7 @@ namespace { // error() - no component specified. _logLines.clear(); error() << "This is logged"; + ASSERT_TRUE(shouldLog(LogSeverity::Error())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " E " << componentB.getNameForLog()), std::string::npos); @@ -83,6 +86,7 @@ namespace { // error() - with component. _logLines.clear(); error(componentA) << "This is logged"; + ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Error())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " E " << componentA.getNameForLog()), std::string::npos); @@ -90,6 +94,7 @@ namespace { // warning() - no component specified. _logLines.clear(); warning() << "This is logged"; + ASSERT_TRUE(shouldLog(LogSeverity::Warning())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " W " << componentB.getNameForLog()), std::string::npos); @@ -97,6 +102,7 @@ namespace { // warning() - with component. _logLines.clear(); warning(componentA) << "This is logged"; + ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Warning())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " W " << componentA.getNameForLog()), std::string::npos); @@ -104,6 +110,7 @@ namespace { // log() - no component specified. _logLines.clear(); log() << "This is logged"; + ASSERT_TRUE(shouldLog(LogSeverity::Log())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " I " << componentB.getNameForLog()), std::string::npos); @@ -111,6 +118,7 @@ namespace { // log() - with component. _logLines.clear(); log(componentA) << "This is logged"; + ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Log())); ASSERT_EQUALS(1U, _logLines.size()); ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " I " << componentA.getNameForLog()), std::string::npos); diff --git a/src/mongo/logger/log_test.cpp b/src/mongo/logger/log_test.cpp index 040124c464f..4d616a1a42b 100644 --- a/src/mongo/logger/log_test.cpp +++ b/src/mongo/logger/log_test.cpp @@ -216,10 +216,10 @@ namespace { LogComponentSettings settings; // Initial log severity for LogComponent::kDefault is Log(). - ASSERT_TRUE(settings.shouldLog(LogSeverity::Info())); - ASSERT_TRUE(settings.shouldLog(LogSeverity::Log())); - ASSERT_FALSE(settings.shouldLog(LogSeverity::Debug(1))); - ASSERT_FALSE(settings.shouldLog(LogSeverity::Debug(2))); + ASSERT_TRUE(shouldLog(LogSeverity::Info())); + ASSERT_TRUE(shouldLog(LogSeverity::Log())); + ASSERT_FALSE(shouldLog(LogSeverity::Debug(1))); + ASSERT_FALSE(shouldLog(LogSeverity::Debug(2))); // If any components are provided to shouldLog(), we should get the same outcome // because we have not configured any non-LogComponent::kDefault components. @@ -228,10 +228,17 @@ namespace { // Set minimum logged severity so that Debug(1) messages are written to log domain. settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1)); - ASSERT_TRUE(settings.shouldLog(LogSeverity::Info())); - ASSERT_TRUE(settings.shouldLog(LogSeverity::Log())); - ASSERT_TRUE(settings.shouldLog(LogSeverity::Debug(1))); - ASSERT_FALSE(settings.shouldLog(LogSeverity::Debug(2))); + logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, + LogSeverity::Debug(1)); + + ASSERT_TRUE(shouldLog(LogSeverity::Info())); + ASSERT_TRUE(shouldLog(LogSeverity::Log())); + ASSERT_TRUE(shouldLog(LogSeverity::Debug(1))); + ASSERT_FALSE(shouldLog(LogSeverity::Debug(2))); + + // Revert back. + logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, + LogSeverity::Log()); // Same results when components are supplied to shouldLog(). ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1))); @@ -250,10 +257,6 @@ namespace { settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1)); settings.setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2)); - // Components for log message: LogComponent::kDefault only. - ASSERT_TRUE(settings.shouldLog(LogSeverity::Debug(1))); - ASSERT_FALSE(settings.shouldLog(LogSeverity::Debug(2))); - // Components for log message: componentA only. ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(2))); ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(3))); @@ -262,6 +265,17 @@ namespace { settings.clearMinimumLoggedSeverity(componentA); ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1))); ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2))); + + // Test shouldLog() with global settings. + logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, + LogSeverity::Debug(1)); + + // Components for log message: LogComponent::kDefault only. + ASSERT_TRUE(shouldLog(LogSeverity::Debug(1))); + ASSERT_FALSE(shouldLog(LogSeverity::Debug(2))); + + logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, + LogSeverity::Log()); } // Test for shouldLog() when we have configured multiple components. @@ -276,10 +290,6 @@ namespace { settings.setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2)); settings.setMinimumLoggedSeverity(componentB, LogSeverity::Log()); - // Components for log message: LogComponent::kDefault only. - ASSERT_TRUE(settings.shouldLog(LogSeverity::Debug(1))); - ASSERT_FALSE(settings.shouldLog(LogSeverity::Debug(2))); - // Components for log message: componentA only. ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(2))); ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(3))); @@ -293,6 +303,19 @@ namespace { // shouldLog() falls back on LogComponent::kDefault. ASSERT_TRUE(settings.shouldLog(componentC, LogSeverity::Debug(1))); ASSERT_FALSE(settings.shouldLog(componentC, LogSeverity::Debug(2))); + + // Test shouldLog() with global settings. + logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, + LogSeverity::Debug(1)); + + + // Components for log message: LogComponent::kDefault only. + ASSERT_TRUE(shouldLog(LogSeverity::Debug(1))); + ASSERT_FALSE(shouldLog(LogSeverity::Debug(2))); + + logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, + LogSeverity::Log()); + } // Log component hierarchy. |