diff options
author | Benety Goh <benety@mongodb.com> | 2014-06-27 19:18:09 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2014-06-30 16:07:45 -0400 |
commit | 30ac4291346859a24fbd5f17b8b99ca598bcab69 (patch) | |
tree | e0e6e90a23fd86778f0112f562ea506588766f33 /src/mongo/logger/log_test.cpp | |
parent | a353e16805d573af3d5ab4d32fbda87ec98d5c40 (diff) | |
download | mongo-30ac4291346859a24fbd5f17b8b99ca598bcab69.tar.gz |
SERVER-5092 renamed LogTag to LogComponent
Diffstat (limited to 'src/mongo/logger/log_test.cpp')
-rw-r--r-- | src/mongo/logger/log_test.cpp | 284 |
1 files changed, 145 insertions, 139 deletions
diff --git a/src/mongo/logger/log_test.cpp b/src/mongo/logger/log_test.cpp index 26d6bce05d0..3b3f9b74c47 100644 --- a/src/mongo/logger/log_test.cpp +++ b/src/mongo/logger/log_test.cpp @@ -33,8 +33,8 @@ #include "mongo/logger/appender.h" #include "mongo/logger/encoder.h" -#include "mongo/logger/log_tag.h" -#include "mongo/logger/log_tag_settings.h" +#include "mongo/logger/log_component.h" +#include "mongo/logger/log_component_settings.h" #include "mongo/logger/message_event_utf8_encoder.h" #include "mongo/logger/message_log_domain.h" #include "mongo/logger/rotatable_file_appender.h" @@ -161,15 +161,15 @@ namespace { B() { log() << "Exercising initializer time logging."; } } b; - // Constants for log tag test cases. - const LogTag tagA = LogTag::kCommands; - const LogTag tagB = LogTag::kAccessControl; - const LogTag tagC = LogTag::kNetworking; + // Constants for log component test cases. + const LogComponent componentA = LogComponent::kCommands; + const LogComponent componentB = LogComponent::kAccessControl; + const LogComponent componentC = LogComponent::kNetworking; - // No log tag declared at file scope. - // Tag severity configuration: - // LogTag::kDefault: 2 - TEST_F(LogTest, MongoLogMacroNoFileScopeLogTag) { + // No log component declared at file scope. + // Component severity configuration: + // LogComponent::kDefault: 2 + TEST_F(LogTest, MongoLogMacroNoFileScopeLogComponent) { globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(2)); LOG(2) << "This is logged"; @@ -177,259 +177,265 @@ namespace { ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG + // MONGO_LOG_COMPONENT _logLines.clear(); - MONGO_LOG_TAG(2, tagA) << "This is logged"; - MONGO_LOG_TAG(3, tagA) << "This is not logged"; + MONGO_LOG_COMPONENT(2, componentA) << "This is logged"; + MONGO_LOG_COMPONENT(3, componentA) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG2 + // MONGO_LOG_COMPONENT2 _logLines.clear(); - MONGO_LOG_TAG2(2, tagA, tagB) << "This is logged"; - MONGO_LOG_TAG2(3, tagA, tagB) << "This is not logged"; + MONGO_LOG_COMPONENT2(2, componentA, componentB) << "This is logged"; + MONGO_LOG_COMPONENT2(3, componentA, componentB) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG3 + // MONGO_LOG_COMPONENT3 _logLines.clear(); - MONGO_LOG_TAG3(2, tagA, tagB, tagC) << "This is logged"; - MONGO_LOG_TAG3(3, tagA, tagB, tagC) << "This is not logged"; + MONGO_LOG_COMPONENT3(2, componentA, componentB, componentC) << "This is logged"; + MONGO_LOG_COMPONENT3(3, componentA, componentB, componentC) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); } - // Default log tag declared at inner namespace scope (tagB). - // Tag severity configuration: - // LogTag::kDefault: 1 - // tagB: 2 - namespace scoped_default_log_tag_test { + // Default log component declared at inner namespace scope (componentB). + // Component severity configuration: + // LogComponent::kDefault: 1 + // componentB: 2 + namespace scoped_default_log_component_test { - // Set MONGO_LOG's default tag to tagB. - MONGO_LOG_DEFAULT_TAG_FILE(tagB); + // Set MONGO_LOG's default component to componentB. + MONGO_LOG_DEFAULT_COMPONENT_FILE(componentB); - TEST_F(LogTest, MongoLogMacroNamespaceScopeLogTagDeclared) { + TEST_F(LogTest, MongoLogMacroNamespaceScopeLogComponentDeclared) { globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(1)); - globalLogDomain()->setMinimumLoggedSeverity(tagB, + globalLogDomain()->setMinimumLoggedSeverity(componentB, LogSeverity::Debug(2)); - // LOG - uses log tag (tagB) declared in MONGO_LOG_DEFAULT_TAG_FILE. + // LOG - uses log component (componentB) declared in MONGO_LOG_DEFAULT_COMPONENT_FILE. LOG(2) << "This is logged"; LOG(3) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - globalLogDomain()->clearMinimumLoggedSeverity(tagB); + globalLogDomain()->clearMinimumLoggedSeverity(componentB); } - } // namespace scoped_default_log_tag_test + } // namespace scoped_default_log_component_test - // Default log tag declared at function scope (tagA). - // Tag severity configuration: - // LogTag::kDefault: 1 - // tagA: 2 - TEST_F(LogTest, MongoLogMacroFunctionScopeLogTagDeclared) { + // Default log component declared at function scope (componentA). + // Component severity configuration: + // LogComponent::kDefault: 1 + // componentA: 2 + TEST_F(LogTest, MongoLogMacroFunctionScopeLogComponentDeclared) { globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(1)); - globalLogDomain()->setMinimumLoggedSeverity(tagA, LogSeverity::Debug(2)); + globalLogDomain()->setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2)); - // Set MONGO_LOG's default tag to tagA. - MONGO_LOG_DEFAULT_TAG_LOCAL(tagA); + // Set MONGO_LOG's default component to componentA. + MONGO_LOG_DEFAULT_COMPONENT_LOCAL(componentA); - // LOG - uses log tag (tagA) declared in MONGO_LOG_DEFAULT_TAG. + // LOG - uses log component (componentA) declared in MONGO_LOG_DEFAULT_COMPONENT. LOG(2) << "This is logged"; LOG(3) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG - log message tag matches function scope tag. + // MONGO_LOG_COMPONENT - log message component matches function scope component. _logLines.clear(); - MONGO_LOG_TAG(2, tagA) << "This is logged"; - MONGO_LOG_TAG(3, tagA) << "This is not logged"; + MONGO_LOG_COMPONENT(2, componentA) << "This is logged"; + MONGO_LOG_COMPONENT(3, componentA) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG - log message tag not configured - fall back on LogTag::kDefault severity. + // MONGO_LOG_COMPONENT - log message component not configured - fall back on + // LogComponent::kDefault. _logLines.clear(); - MONGO_LOG_TAG(1, tagB) << "This is logged"; - MONGO_LOG_TAG(2, tagB) << "This is not logged"; + MONGO_LOG_COMPONENT(1, componentB) << "This is logged"; + MONGO_LOG_COMPONENT(2, componentB) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG2 + // MONGO_LOG_COMPONENT2 _logLines.clear(); - MONGO_LOG_TAG2(2, tagA, tagB) << "This is logged"; - MONGO_LOG_TAG2(3, tagA, tagB) << "This is not logged"; + MONGO_LOG_COMPONENT2(2, componentA, componentB) << "This is logged"; + MONGO_LOG_COMPONENT2(3, componentA, componentB) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG2 - reverse order. + // MONGO_LOG_COMPONENT2 - reverse order. _logLines.clear(); - MONGO_LOG_TAG2(2, tagB, tagA) << "This is logged"; - MONGO_LOG_TAG2(3, tagB, tagA) << "This is not logged"; + MONGO_LOG_COMPONENT2(2, componentB, componentA) << "This is logged"; + MONGO_LOG_COMPONENT2(3, componentB, componentA) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG2 - none of the log message tags configured - fall back on LogTag::kDefault. + // MONGO_LOG_COMPONENT2 - none of the log message components configured - fall back on + // LogComponent::kDefault. _logLines.clear(); - MONGO_LOG_TAG2(1, tagB, tagC) << "This is logged"; - MONGO_LOG_TAG2(2, tagB, tagC) << "This is not logged"; + MONGO_LOG_COMPONENT2(1, componentB, componentC) << "This is logged"; + MONGO_LOG_COMPONENT2(2, componentB, componentC) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG3 + // MONGO_LOG_COMPONENT3 _logLines.clear(); - MONGO_LOG_TAG3(2, tagA, tagB, tagC) << "This is logged"; - MONGO_LOG_TAG3(3, tagA, tagB, tagC) << "This is not logged"; + MONGO_LOG_COMPONENT3(2, componentA, componentB, componentC) << "This is logged"; + MONGO_LOG_COMPONENT3(3, componentA, componentB, componentC) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG3 - configured tag as 2nd tag. + // MONGO_LOG_COMPONENT3 - configured component as 2nd component. _logLines.clear(); - MONGO_LOG_TAG3(2, tagB, tagA, tagC) << "This is logged"; - MONGO_LOG_TAG3(3, tagB, tagA, tagC) << "This is not logged"; + MONGO_LOG_COMPONENT3(2, componentB, componentA, componentC) << "This is logged"; + MONGO_LOG_COMPONENT3(3, componentB, componentA, componentC) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG3 - configured tag as 3rd tag. + // MONGO_LOG_COMPONENT3 - configured component as 3rd component. _logLines.clear(); - MONGO_LOG_TAG3(2, tagB, tagC, tagA) << "This is logged"; - MONGO_LOG_TAG3(3, tagB, tagC, tagA) << "This is not logged"; + MONGO_LOG_COMPONENT3(2, componentB, componentC, componentA) << "This is logged"; + MONGO_LOG_COMPONENT3(3, componentB, componentC, componentA) << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - // MONGO_LOG_TAG3 - none of the log message tags configured - fall back on LogTag::kDefault. + // MONGO_LOG_COMPONENT3 - none of the log message components configured - fall back on + // LogComponent::kDefault. _logLines.clear(); - MONGO_LOG_TAG3(1, tagB, tagC, LogTag::kIndexing) << "This is logged"; - MONGO_LOG_TAG3(2, tagB, tagC, LogTag::kIndexing) << "This is not logged"; + MONGO_LOG_COMPONENT3(1, componentB, componentC, LogComponent::kIndexing) + << "This is logged"; + MONGO_LOG_COMPONENT3(2, componentB, componentC, LogComponent::kIndexing) + << "This is not logged"; ASSERT_EQUALS(1U, _logLines.size()); ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]); - globalLogDomain()->clearMinimumLoggedSeverity(tagA); + globalLogDomain()->clearMinimumLoggedSeverity(componentA); } // - // Tag log level tests. - // The global log manager holds the tag log level configuration for the global log domain. - // LOG() and MONGO_LOG_TAG() macros in util/log.h determine at runtime if a log message + // Component log level tests. + // The global log manager holds the component log level configuration for the global log domain. + // LOG() and MONGO_LOG_COMPONENT() macros in util/log.h determine at runtime if a log message // should be written to the log domain. // - TEST_F(LogTest, LogTagSettingsMinimumLogSeverity) { - LogTagSettings settings; - ASSERT_TRUE(settings.hasMinimumLogSeverity(LogTag::kDefault)); - ASSERT_TRUE(settings.getMinimumLogSeverity(LogTag::kDefault) == LogSeverity::Log()); - for (int i = 0; i < int(LogTag::kNumLogTags); ++i) { - LogTag tag = static_cast<LogTag::Value>(i); - if (tag == LogTag::kDefault) { continue; } - ASSERT_FALSE(settings.hasMinimumLogSeverity(tag)); + TEST_F(LogTest, LogComponentSettingsMinimumLogSeverity) { + LogComponentSettings settings; + ASSERT_TRUE(settings.hasMinimumLogSeverity(LogComponent::kDefault)); + ASSERT_TRUE(settings.getMinimumLogSeverity(LogComponent::kDefault) == LogSeverity::Log()); + for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) { + LogComponent component = static_cast<LogComponent::Value>(i); + if (component == LogComponent::kDefault) { continue; } + ASSERT_FALSE(settings.hasMinimumLogSeverity(component)); } // Override and clear minimum severity level. - for (int i = 0; i < int(LogTag::kNumLogTags); ++i) { - LogTag tag = static_cast<LogTag::Value>(i); + for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) { + LogComponent component = static_cast<LogComponent::Value>(i); LogSeverity severity = LogSeverity::Debug(2); // Override severity level. - settings.setMinimumLoggedSeverity(tag, severity); - ASSERT_TRUE(settings.hasMinimumLogSeverity(tag)); - ASSERT_TRUE(settings.getMinimumLogSeverity(tag) == severity); + settings.setMinimumLoggedSeverity(component, severity); + ASSERT_TRUE(settings.hasMinimumLogSeverity(component)); + ASSERT_TRUE(settings.getMinimumLogSeverity(component) == severity); // Clear severity level. - // Special case: when clearing LogTag::kDefault, the corresponding + // Special case: when clearing LogComponent::kDefault, the corresponding // severity level is set to default values (ie. Log()). - settings.clearMinimumLoggedSeverity(tag); - if (tag == LogTag::kDefault) { - ASSERT_TRUE(settings.hasMinimumLogSeverity(tag)); - ASSERT_TRUE(settings.getMinimumLogSeverity(LogTag::kDefault) == LogSeverity::Log()); + settings.clearMinimumLoggedSeverity(component); + if (component == LogComponent::kDefault) { + ASSERT_TRUE(settings.hasMinimumLogSeverity(component)); + ASSERT_TRUE(settings.getMinimumLogSeverity(LogComponent::kDefault) == + LogSeverity::Log()); } else { - ASSERT_FALSE(settings.hasMinimumLogSeverity(tag)); + ASSERT_FALSE(settings.hasMinimumLogSeverity(component)); } } } - // Test for shouldLog() when the minimum logged severity is set only for LogTag::kDefault. - TEST_F(LogTest, LogTagSettingsShouldLogDefaultLogTagOnly) { - LogTagSettings settings; + // Test for shouldLog() when the minimum logged severity is set only for LogComponent::kDefault. + TEST_F(LogTest, LogComponentSettingsShouldLogDefaultLogComponentOnly) { + LogComponentSettings settings; - // Initial log severity for LogTag::kDefault is Log(). + // 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))); - // If any tags are provided to shouldLog(), we should get the same outcome - // because we have not configured any non-LogTag::kDefault tags. - ASSERT_TRUE(settings.shouldLog(tagA, LogSeverity::Log())); - ASSERT_FALSE(settings.shouldLog(tagA, LogSeverity::Debug(1))); + // If any components are provided to shouldLog(), we should get the same outcome + // because we have not configured any non-LogComponent::kDefault components. + ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Log())); + ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(1))); // Set minimum logged severity so that Debug(1) messages are written to log domain. - settings.setMinimumLoggedSeverity(LogTag::kDefault, LogSeverity::Debug(1)); + 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))); - // Same results when tags are supplied to shouldLog(). - ASSERT_TRUE(settings.shouldLog(tagA, LogSeverity::Debug(1))); - ASSERT_FALSE(settings.shouldLog(tagA, LogSeverity::Debug(2))); + // Same results when components are supplied to shouldLog(). + ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1))); + ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2))); } - // Test for shouldLog() when we have configured a single tag. - // Also checks that severity level has been reverted to match LogTag::kDefault + // Test for shouldLog() when we have configured a single component. + // Also checks that severity level has been reverted to match LogComponent::kDefault // after clearing level. // Minimum severity levels: - // LogTag::kDefault: 1 - // tagA: 2 - TEST_F(LogTest, LogTagSettingsShouldLogSingleTag) { - LogTagSettings settings; + // LogComponent::kDefault: 1 + // componentA: 2 + TEST_F(LogTest, LogComponentSettingsShouldLogSingleComponent) { + LogComponentSettings settings; - settings.setMinimumLoggedSeverity(LogTag::kDefault, LogSeverity::Debug(1)); - settings.setMinimumLoggedSeverity(tagA, LogSeverity::Debug(2)); + settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1)); + settings.setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2)); - // Tags for log message: LogTag::kDefault only. + // Components for log message: LogComponent::kDefault only. ASSERT_TRUE(settings.shouldLog(LogSeverity::Debug(1))); ASSERT_FALSE(settings.shouldLog(LogSeverity::Debug(2))); - // Tags for log message: tagA only. - ASSERT_TRUE(settings.shouldLog(tagA, LogSeverity::Debug(2))); - ASSERT_FALSE(settings.shouldLog(tagA, LogSeverity::Debug(3))); + // Components for log message: componentA only. + ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(2))); + ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(3))); - // Clear severity level for tagA and check shouldLog() again. - settings.clearMinimumLoggedSeverity(tagA); - ASSERT_TRUE(settings.shouldLog(tagA, LogSeverity::Debug(1))); - ASSERT_FALSE(settings.shouldLog(tagA, LogSeverity::Debug(2))); + // Clear severity level for componentA and check shouldLog() again. + settings.clearMinimumLoggedSeverity(componentA); + ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1))); + ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2))); } - // Test for shouldLog() when we have configured multiple tags. + // Test for shouldLog() when we have configured multiple components. // Minimum severity levels: - // LogTag::kDefault: 1 - // tagA: 2 - // tagB: 0 - TEST_F(LogTest, LogTagSettingsShouldLogMultipleTagsConfigured) { - LogTagSettings settings; + // LogComponent::kDefault: 1 + // componentA: 2 + // componentB: 0 + TEST_F(LogTest, LogComponentSettingsShouldLogMultipleComponentsConfigured) { + LogComponentSettings settings; - settings.setMinimumLoggedSeverity(LogTag::kDefault, LogSeverity::Debug(1)); - settings.setMinimumLoggedSeverity(tagA, LogSeverity::Debug(2)); - settings.setMinimumLoggedSeverity(tagB, LogSeverity::Log()); + settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1)); + settings.setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2)); + settings.setMinimumLoggedSeverity(componentB, LogSeverity::Log()); - // Tags for log message: LogTag::kDefault only. + // Components for log message: LogComponent::kDefault only. ASSERT_TRUE(settings.shouldLog(LogSeverity::Debug(1))); ASSERT_FALSE(settings.shouldLog(LogSeverity::Debug(2))); - // Tags for log message: tagA only. - ASSERT_TRUE(settings.shouldLog(tagA, LogSeverity::Debug(2))); - ASSERT_FALSE(settings.shouldLog(tagA, LogSeverity::Debug(3))); + // Components for log message: componentA only. + ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(2))); + ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(3))); - // Tags for log message: tagB only. - ASSERT_TRUE(settings.shouldLog(tagB, LogSeverity::Log())); - ASSERT_FALSE(settings.shouldLog(tagB, LogSeverity::Debug(1))); + // Components for log message: componentB only. + ASSERT_TRUE(settings.shouldLog(componentB, LogSeverity::Log())); + ASSERT_FALSE(settings.shouldLog(componentB, LogSeverity::Debug(1))); - // Tags for log message: tagC only. - // Since a tag-specific minimum severity is not configured for tagC, - // shouldLog() falls back on LogTag::kDefault. - ASSERT_TRUE(settings.shouldLog(tagC, LogSeverity::Debug(1))); - ASSERT_FALSE(settings.shouldLog(tagC, LogSeverity::Debug(2))); + // Components for log message: componentC only. + // Since a component-specific minimum severity is not configured for componentC, + // shouldLog() falls back on LogComponent::kDefault. + ASSERT_TRUE(settings.shouldLog(componentC, LogSeverity::Debug(1))); + ASSERT_FALSE(settings.shouldLog(componentC, LogSeverity::Debug(2))); } } // namespace |