diff options
-rw-r--r-- | src/mongo/db/commands/parameters.cpp | 36 | ||||
-rw-r--r-- | src/mongo/logger/SConscript | 6 | ||||
-rw-r--r-- | src/mongo/logger/component_message_log_domain.cpp | 87 | ||||
-rw-r--r-- | src/mongo/logger/component_message_log_domain.h (renamed from src/mongo/logger/tag_message_log_domain.h) | 34 | ||||
-rw-r--r-- | src/mongo/logger/log_component.cpp (renamed from src/mongo/logger/log_tag.cpp) | 8 | ||||
-rw-r--r-- | src/mongo/logger/log_component.h (renamed from src/mongo/logger/log_tag.h) | 18 | ||||
-rw-r--r-- | src/mongo/logger/log_component_settings.cpp | 107 | ||||
-rw-r--r-- | src/mongo/logger/log_component_settings.h (renamed from src/mongo/logger/log_tag_settings.h) | 59 | ||||
-rw-r--r-- | src/mongo/logger/log_manager.h | 6 | ||||
-rw-r--r-- | src/mongo/logger/log_tag_settings.cpp | 105 | ||||
-rw-r--r-- | src/mongo/logger/log_test.cpp | 284 | ||||
-rw-r--r-- | src/mongo/logger/logger.h | 2 | ||||
-rw-r--r-- | src/mongo/logger/tag_message_log_domain.cpp | 82 | ||||
-rw-r--r-- | src/mongo/util/log.h | 43 |
14 files changed, 451 insertions, 426 deletions
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp index 479e56e3d96..ff5ac1ef54c 100644 --- a/src/mongo/db/commands/parameters.cpp +++ b/src/mongo/db/commands/parameters.cpp @@ -249,24 +249,24 @@ namespace mongo { } logLevelSetting; /** - * Tag log levels. - * Non-negative value means this tag is configured with a debug level. - * Negative value means log messages with this tag will use the default log level. + * Component log levels. + * Non-negative value means this component is configured with a debug level. + * Negative value means log messages with this component will use the default log level. */ - class TagLogLevelSetting : public ServerParameter { - MONGO_DISALLOW_COPYING(TagLogLevelSetting); + class ComponentLogLevelSetting : public ServerParameter { + MONGO_DISALLOW_COPYING(ComponentLogLevelSetting); public: - explicit TagLogLevelSetting(logger::LogTag tag) + explicit ComponentLogLevelSetting(logger::LogComponent component) : ServerParameter(ServerParameterSet::getGlobal(), - "logLevel_" + tag.getShortName()), - _tag(tag) {} + "logLevel_" + component.getShortName()), + _component(component) {} virtual void append(OperationContext* txn, BSONObjBuilder& b, const std::string& name) { - if (!logger::globalLogDomain()->hasMinimumLogSeverity(_tag)) { + if (!logger::globalLogDomain()->hasMinimumLogSeverity(_component)) { b << name << -1; return; } - b << name << logger::globalLogDomain()->getMinimumLogSeverity(_tag).toInt(); + b << name << logger::globalLogDomain()->getMinimumLogSeverity(_component).toInt(); } virtual Status set(const BSONElement& newValueElement) { @@ -290,16 +290,16 @@ namespace mongo { private: Status _setLogLevel(int newValue) { if (newValue < 0) { - logger::globalLogDomain()->clearMinimumLoggedSeverity(_tag); + logger::globalLogDomain()->clearMinimumLoggedSeverity(_component); return Status::OK(); } typedef logger::LogSeverity LogSeverity; LogSeverity newSeverity = (newValue > 0) ? LogSeverity::Debug(newValue) : LogSeverity::Log(); - logger::globalLogDomain()->setMinimumLoggedSeverity(_tag, newSeverity); + logger::globalLogDomain()->setMinimumLoggedSeverity(_component, newSeverity); return Status::OK(); } - logger::LogTag _tag; + logger::LogComponent _component; }; class SSLModeSetting : public ServerParameter { @@ -483,12 +483,12 @@ namespace mongo { // available to the client. // - MONGO_INITIALIZER_WITH_PREREQUISITES(SetupTagLogLevelSettings, + MONGO_INITIALIZER_WITH_PREREQUISITES(SetupComponentLogLevelSettings, MONGO_NO_PREREQUISITES)(InitializerContext* context) { - for (int i = 0; i < int(logger::LogTag::kNumLogTags); ++i) { - logger::LogTag tag = static_cast<logger::LogTag::Value>(i); - if (tag == logger::LogTag::kDefault) { continue; } - new TagLogLevelSetting(tag); + for (int i = 0; i < int(logger::LogComponent::kNumLogComponents); ++i) { + logger::LogComponent component = static_cast<logger::LogComponent::Value>(i); + if (component == logger::LogComponent::kDefault) { continue; } + new ComponentLogLevelSetting(component); } return Status::OK(); diff --git a/src/mongo/logger/SConscript b/src/mongo/logger/SConscript index 926d3c68350..482d753595e 100644 --- a/src/mongo/logger/SConscript +++ b/src/mongo/logger/SConscript @@ -7,13 +7,13 @@ env.Library('logger', 'console.cpp', 'log_manager.cpp', 'log_severity.cpp', - 'log_tag.cpp', - 'log_tag_settings.cpp', + 'log_component.cpp', + 'log_component_settings.cpp', 'logger.cpp', 'logstream_builder.cpp', 'message_event_utf8_encoder.cpp', 'message_log_domain.cpp', - 'tag_message_log_domain.cpp', + 'component_message_log_domain.cpp', 'ramlog.cpp', 'rotatable_file_manager.cpp', 'rotatable_file_writer.cpp', diff --git a/src/mongo/logger/component_message_log_domain.cpp b/src/mongo/logger/component_message_log_domain.cpp new file mode 100644 index 00000000000..c22617e651f --- /dev/null +++ b/src/mongo/logger/component_message_log_domain.cpp @@ -0,0 +1,87 @@ +/* Copyright 2014 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects + * for all of the code used other than as permitted herein. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you do not + * wish to do so, delete this exception statement from your version. If you + * delete this exception statement from all source files in the program, + * then also delete it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/logger/component_message_log_domain.h" + +namespace mongo { +namespace logger { + + ComponentMessageLogDomain::ComponentMessageLogDomain() {} + + ComponentMessageLogDomain::~ComponentMessageLogDomain() {} + + bool ComponentMessageLogDomain::hasMinimumLogSeverity(LogComponent component) const { + 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); + } + + bool ComponentMessageLogDomain::shouldLog(LogComponent component1, LogComponent component2, + LogSeverity severity) const { + return _settings.shouldLog(component1, severity) || + _settings.shouldLog(component2, severity); + } + + bool ComponentMessageLogDomain::shouldLog(LogComponent component1, LogComponent component2, + LogComponent component3, + LogSeverity severity) const { + return _settings.shouldLog(component1, severity) || + _settings.shouldLog(component2, severity) || + _settings.shouldLog(component3, severity); + } + + LogSeverity ComponentMessageLogDomain::getMinimumLogSeverity() const { + return _settings.getMinimumLogSeverity(LogComponent::kDefault); + } + + LogSeverity ComponentMessageLogDomain::getMinimumLogSeverity(LogComponent component) const { + return _settings.getMinimumLogSeverity(component); + } + + void ComponentMessageLogDomain::setMinimumLoggedSeverity(LogSeverity severity) { + _settings.setMinimumLoggedSeverity(LogComponent::kDefault, severity); + } + + void ComponentMessageLogDomain::setMinimumLoggedSeverity(LogComponent component, + LogSeverity severity) { + _settings.setMinimumLoggedSeverity(component, severity); + } + + void ComponentMessageLogDomain::clearMinimumLoggedSeverity(LogComponent component) { + _settings.clearMinimumLoggedSeverity(component); + } + +} // namespace logger +} // namespace mongo diff --git a/src/mongo/logger/tag_message_log_domain.h b/src/mongo/logger/component_message_log_domain.h index 59e419d4700..79be26380e2 100644 --- a/src/mongo/logger/tag_message_log_domain.h +++ b/src/mongo/logger/component_message_log_domain.h @@ -27,7 +27,7 @@ #pragma once -#include "mongo/logger/log_tag_settings.h" +#include "mongo/logger/log_component_settings.h" #include "mongo/logger/message_log_domain.h" namespace mongo { @@ -36,48 +36,50 @@ namespace logger { /** * Logging domain for ephemeral messages with minimum severity. */ - class TagMessageLogDomain : public MessageLogDomain { - MONGO_DISALLOW_COPYING(TagMessageLogDomain); + class ComponentMessageLogDomain : public MessageLogDomain { + MONGO_DISALLOW_COPYING(ComponentMessageLogDomain); public: - TagMessageLogDomain(); + ComponentMessageLogDomain(); - ~TagMessageLogDomain(); + ~ComponentMessageLogDomain(); /** * 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(LogTag tag, LogSeverity severity) const; - bool shouldLog(LogTag tag1, LogTag tag2, LogSeverity severity) const; - bool shouldLog(LogTag tag1, LogTag tag2, LogTag tag3, LogSeverity severity) const; + bool shouldLog(LogComponent component, LogSeverity severity) const; + bool shouldLog(LogComponent component1, LogComponent component2, + LogSeverity severity) const; + bool shouldLog(LogComponent component1, LogComponent component2, LogComponent component3, + LogSeverity severity) const; /** - * Returns true if a minimum log severity has been set for this tag. - * Called by log level commands to query tag severity configuration. + * Returns true if a minimum log severity has been set for this component. + * Called by log level commands to query component severity configuration. */ - bool hasMinimumLogSeverity(LogTag tag) const; + bool hasMinimumLogSeverity(LogComponent component) const; /** * Gets the minimum severity of messages that should be sent to this LogDomain. */ LogSeverity getMinimumLogSeverity() const; - LogSeverity getMinimumLogSeverity(LogTag tag) const; + LogSeverity getMinimumLogSeverity(LogComponent component) const; /** * Sets the minimum severity of messages that should be sent to this LogDomain. */ void setMinimumLoggedSeverity(LogSeverity severity); - void setMinimumLoggedSeverity(LogTag, LogSeverity severity); + void setMinimumLoggedSeverity(LogComponent, LogSeverity severity); /** - * Clears the minimum log severity for tag. + * Clears the minimum log severity for component. * For kDefault, severity level is initialized to default value. */ - void clearMinimumLoggedSeverity(LogTag tag); + void clearMinimumLoggedSeverity(LogComponent component); private: - LogTagSettings _settings; + LogComponentSettings _settings; }; } // namespace logger diff --git a/src/mongo/logger/log_tag.cpp b/src/mongo/logger/log_component.cpp index f2df1d7585e..8df78c3827c 100644 --- a/src/mongo/logger/log_tag.cpp +++ b/src/mongo/logger/log_component.cpp @@ -27,14 +27,14 @@ #include "mongo/platform/basic.h" -#include "mongo/logger/log_tag.h" +#include "mongo/logger/log_component.h" #include "mongo/util/assert_util.h" namespace mongo { namespace logger { - std::string LogTag::getShortName() const { + std::string LogComponent::getShortName() const { switch (_value) { case kDefault: return "Default"; case kAccessControl: return "AccessControl"; @@ -47,8 +47,8 @@ namespace logger { case kSharding: return "Sharding"; case kStorage: return "Storage"; case kWrites: return "Writes"; - case kNumLogTags: return "Total"; - // No default. Compiler should complain if there's a tag that's not handled. + case kNumLogComponents: return "Total"; + // No default. Compiler should complain if there's a log component that's not handled. } invariant(0); } diff --git a/src/mongo/logger/log_tag.h b/src/mongo/logger/log_component.h index 06e39613833..adf2f43a145 100644 --- a/src/mongo/logger/log_tag.h +++ b/src/mongo/logger/log_component.h @@ -33,11 +33,11 @@ namespace mongo { namespace logger { /** - * Log tags. - * Debug messages logged using the LOG() or MONGO_LOG_TAG() - * macros may be associated with one or more log tags. + * Log components. + * Debug messages logged using the LOG() or MONGO_LOG_COMPONENT(). + * Macros may be associated with one or more log components. */ - class LogTag { + class LogComponent { public: enum Value { kDefault = 0, @@ -51,16 +51,16 @@ namespace logger { kSharding, kStorage, kWrites, - kNumLogTags + kNumLogComponents }; - /* implicit */ LogTag(Value value) : _value(value) {} + /* implicit */ LogComponent(Value value) : _value(value) {} operator Value() const { return _value; } /** - * Returns short name of log tag. - * Used to generate server parameter names in the format "logLevel_<tag short name>". + * Returns short name of log component. + * Used to generate server parameter names in the format "logLevel_<component short name>". */ std::string getShortName() const; @@ -68,5 +68,7 @@ namespace logger { Value _value; }; + typedef LogComponent LogTag; + } // namespace logger } // namespace mongo diff --git a/src/mongo/logger/log_component_settings.cpp b/src/mongo/logger/log_component_settings.cpp new file mode 100644 index 00000000000..ab62f54d3bb --- /dev/null +++ b/src/mongo/logger/log_component_settings.cpp @@ -0,0 +1,107 @@ +/* Copyright 2014 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects + * for all of the code used other than as permitted herein. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you do not + * wish to do so, delete this exception statement from your version. If you + * delete this exception statement from all source files in the program, + * then also delete it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/logger/log_component_settings.h" + +#include "mongo/util/assert_util.h" + +namespace mongo { +namespace logger { + + LogComponentSettings::LogComponentSettings() { + _minimumLoggedSeverity[LogComponent::kDefault] = char(LogSeverity::Log().toInt()); + + for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) { + _minimumLoggedSeverity[i] = _minimumLoggedSeverity[LogComponent::kDefault]; + _hasMinimumLoggedSeverity[i] = false; + } + + _hasMinimumLoggedSeverity[LogComponent::kDefault] = true; + } + + LogComponentSettings::~LogComponentSettings() { } + + bool LogComponentSettings::hasMinimumLogSeverity(LogComponent component) const { + dassert(int(component) >= 0 && int(component) < LogComponent::kNumLogComponents); + return _hasMinimumLoggedSeverity[component]; + } + + LogSeverity LogComponentSettings::getMinimumLogSeverity(LogComponent component) const { + dassert(int(component) >= 0 && int(component) < LogComponent::kNumLogComponents); + return LogSeverity::cast(_minimumLoggedSeverity[component]); + } + + void LogComponentSettings::setMinimumLoggedSeverity(LogComponent component, + LogSeverity severity) { + dassert(int(component) >= 0 && int(component) < LogComponent::kNumLogComponents); + _minimumLoggedSeverity[component] = char(severity.toInt()); + _hasMinimumLoggedSeverity[component] = true; + + // Set severities for unconfigured components to be the same as LogComponent::kDefault. + if (component == LogComponent::kDefault) { + for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) { + if (!_hasMinimumLoggedSeverity[i]) { + _minimumLoggedSeverity[i] = char(severity.toInt()); + } + } + } + } + + void LogComponentSettings::clearMinimumLoggedSeverity(LogComponent component) { + dassert(int(component) >= 0 && int(component) < LogComponent::kNumLogComponents); + + // LogComponent::kDefault must always be configured. + if (component == LogComponent::kDefault) { + setMinimumLoggedSeverity(component, LogSeverity::Log()); + return; + } + + // Set unconfigured severity level to match LogComponent::kDefault. + _minimumLoggedSeverity[component] = _minimumLoggedSeverity[LogComponent::kDefault]; + _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); + + // Should match LogComponent::kDefault if minimum severity level is not configured for + // component. + dassert(_hasMinimumLoggedSeverity[component] || + _minimumLoggedSeverity[component] == + _minimumLoggedSeverity[LogComponent::kDefault]); + + return severity >= LogSeverity::cast(_minimumLoggedSeverity[component]); + } + +} // logger +} // mongo diff --git a/src/mongo/logger/log_tag_settings.h b/src/mongo/logger/log_component_settings.h index abed408c42f..616ae494bf9 100644 --- a/src/mongo/logger/log_tag_settings.h +++ b/src/mongo/logger/log_component_settings.h @@ -28,70 +28,71 @@ #pragma once #include "mongo/base/disallow_copying.h" -#include "mongo/logger/log_tag.h" +#include "mongo/logger/log_component.h" #include "mongo/logger/log_severity.h" namespace mongo { namespace logger { /** - * Contains log severities for a list of log tags. + * Contains log severities for a list of log components. * kDefault always has a log severity defined but it is not necessary to - * provide log severities for the other tags (up to but not including kNumLogTags). + * provide log severities for the other components (up to but not including kNumLogComponents). */ - class LogTagSettings { - MONGO_DISALLOW_COPYING(LogTagSettings); + class LogComponentSettings { + MONGO_DISALLOW_COPYING(LogComponentSettings); public: - LogTagSettings(); - ~LogTagSettings(); + LogComponentSettings(); + ~LogComponentSettings(); /** - * Returns true if a minimum log severity has been set for this tag. - * Used by log level commands to query tag severity configuration. + * Returns true if a minimum log severity has been set for this component. + * Used by log level commands to query component severity configuration. */ - bool hasMinimumLogSeverity(LogTag tag) const; + bool hasMinimumLogSeverity(LogComponent component) const; /** - * Gets the minimum log severity for tag. - * Result is defined only if hasMinimumLogSeverity() returns true for tag. + * Gets the minimum log severity for component. + * Result is defined only if hasMinimumLogSeverity() returns true for component. */ - LogSeverity getMinimumLogSeverity(LogTag tag) const; + LogSeverity getMinimumLogSeverity(LogComponent component) const; /** - * Sets the minimum log severity for tag. + * Sets the minimum log severity for component. */ - void setMinimumLoggedSeverity(LogTag tag, LogSeverity severity); + void setMinimumLoggedSeverity(LogComponent component, LogSeverity severity); /** - * Clears the minimum log severity for tag. + * Clears the minimum log severity for component. * For kDefault, severity level is initialized to default value. */ - void clearMinimumLoggedSeverity(LogTag tag); + void clearMinimumLoggedSeverity(LogComponent component); /** * Predicate that answers the question, "Should I, the caller, append to you, the log - * domain, tagged messages of the given severity?" True means yes. + * domain, componentged messages of the given severity?" True means yes. * - * No tags provided means to check against kDefault only. + * No components provided means to check against kDefault only. * - * If a tag is specified but minimum severity levels are not configured, + * If a component is specified but minimum severity levels are not configured, * compare 'severity' against the configured level for kDefault. */ bool shouldLog(LogSeverity severity) const; - bool shouldLog(LogTag tag, LogSeverity severity) const; + bool shouldLog(LogComponent component, LogSeverity severity) const; private: - // True if a log severity is explicitly set for a tag. - // This differentiates between unconfigured tags and tags that happen to have the same - // severity as kDefault. - // This is also used to update the severities of unconfigured tags when the severity for - // kDefault is modified. - bool _hasMinimumLoggedSeverity[LogTag::kNumLogTags]; + // True if a log severity is explicitly set for a component. + // This differentiates between unconfigured components and components that happen to have + // the same severity as kDefault. + // This is also used to update the severities of unconfigured components when the severity + // for kDefault is modified. + bool _hasMinimumLoggedSeverity[LogComponent::kNumLogComponents]; - // Log severities for tags. + // Log severities for components. // Store numerical values of severities to be cache-line friendly. // Set to kDefault minimum logged severity if _hasMinimumLoggedSeverity[i] is false. - char _minimumLoggedSeverity[LogTag::kNumLogTags]; + char _minimumLoggedSeverity[LogComponent::kNumLogComponents]; }; + } // namespace logger } // namespace mongo diff --git a/src/mongo/logger/log_manager.h b/src/mongo/logger/log_manager.h index bdef7870b9b..79181771f5e 100644 --- a/src/mongo/logger/log_manager.h +++ b/src/mongo/logger/log_manager.h @@ -30,7 +30,7 @@ #include <string> #include "mongo/base/disallow_copying.h" -#include "mongo/logger/tag_message_log_domain.h" +#include "mongo/logger/component_message_log_domain.h" #include "mongo/logger/rotatable_file_writer.h" #include "mongo/platform/unordered_map.h" @@ -51,7 +51,7 @@ namespace logger { /** * Gets the global domain for this manager. It has no name. */ - TagMessageLogDomain* getGlobalDomain() { return &_globalDomain; } + ComponentMessageLogDomain* getGlobalDomain() { return &_globalDomain; } /** * Get the log domain with the given name, creating if needed. @@ -62,7 +62,7 @@ namespace logger { typedef unordered_map<std::string, MessageLogDomain*> DomainsByNameMap; DomainsByNameMap _domains; - TagMessageLogDomain _globalDomain; + ComponentMessageLogDomain _globalDomain; }; } // namespace logger diff --git a/src/mongo/logger/log_tag_settings.cpp b/src/mongo/logger/log_tag_settings.cpp deleted file mode 100644 index 82ff1f48357..00000000000 --- a/src/mongo/logger/log_tag_settings.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* Copyright 2014 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects - * for all of the code used other than as permitted herein. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you do not - * wish to do so, delete this exception statement from your version. If you - * delete this exception statement from all source files in the program, - * then also delete it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/logger/log_tag_settings.h" - -#include "mongo/util/assert_util.h" - -namespace mongo { -namespace logger { - - LogTagSettings::LogTagSettings() { - _minimumLoggedSeverity[LogTag::kDefault] = char(LogSeverity::Log().toInt()); - - for (int i = 0; i < int(LogTag::kNumLogTags); ++i) { - _minimumLoggedSeverity[i] = _minimumLoggedSeverity[LogTag::kDefault]; - _hasMinimumLoggedSeverity[i] = false; - } - - _hasMinimumLoggedSeverity[LogTag::kDefault] = true; - } - - LogTagSettings::~LogTagSettings() { } - - bool LogTagSettings::hasMinimumLogSeverity(LogTag tag) const { - dassert(int(tag) >= 0 && int(tag) < LogTag::kNumLogTags); - return _hasMinimumLoggedSeverity[tag]; - } - - LogSeverity LogTagSettings::getMinimumLogSeverity(LogTag tag) const { - dassert(int(tag) >= 0 && int(tag) < LogTag::kNumLogTags); - return LogSeverity::cast(_minimumLoggedSeverity[tag]); - } - - void LogTagSettings::setMinimumLoggedSeverity(LogTag tag, LogSeverity severity) { - dassert(int(tag) >= 0 && int(tag) < LogTag::kNumLogTags); - _minimumLoggedSeverity[tag] = char(severity.toInt()); - _hasMinimumLoggedSeverity[tag] = true; - - // Set severities for unconfigured tags to be the same as LogTag::kDefault. - if (tag == LogTag::kDefault) { - for (int i = 0; i < int(LogTag::kNumLogTags); ++i) { - if (!_hasMinimumLoggedSeverity[i]) { - _minimumLoggedSeverity[i] = char(severity.toInt()); - } - } - } - } - - void LogTagSettings::clearMinimumLoggedSeverity(LogTag tag) { - dassert(int(tag) >= 0 && int(tag) < LogTag::kNumLogTags); - - // LogTag::kDefault must always be configured. - if (tag == LogTag::kDefault) { - setMinimumLoggedSeverity(tag, LogSeverity::Log()); - return; - } - - // Set unconfigured severity level to match LogTag::kDefault. - _minimumLoggedSeverity[tag] = _minimumLoggedSeverity[LogTag::kDefault]; - _hasMinimumLoggedSeverity[tag] = false; - } - - bool LogTagSettings::shouldLog(LogSeverity severity) const { - return severity >= LogSeverity::cast(_minimumLoggedSeverity[LogTag::kDefault]); - } - - bool LogTagSettings::shouldLog(LogTag tag, LogSeverity severity) const { - dassert(int(tag) >= 0 && int(tag) < LogTag::kNumLogTags); - - // Should match LogTag::kDefault if minimum severity level is not configured for tag. - dassert(_hasMinimumLoggedSeverity[tag] || - _minimumLoggedSeverity[tag] == - _minimumLoggedSeverity[LogTag::kDefault]); - - return severity >= LogSeverity::cast(_minimumLoggedSeverity[tag]); - } - -} // logger -} // mongo 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 diff --git a/src/mongo/logger/logger.h b/src/mongo/logger/logger.h index c3077a14102..29f8de3e833 100644 --- a/src/mongo/logger/logger.h +++ b/src/mongo/logger/logger.h @@ -48,7 +48,7 @@ namespace logger { /** * Gets the global MessageLogDomain associated for the global log manager. */ - inline TagMessageLogDomain* globalLogDomain() { return globalLogManager()->getGlobalDomain(); } + inline ComponentMessageLogDomain* globalLogDomain() { return globalLogManager()->getGlobalDomain(); } } // namespace logger } // namespace mongo diff --git a/src/mongo/logger/tag_message_log_domain.cpp b/src/mongo/logger/tag_message_log_domain.cpp deleted file mode 100644 index 00ca1c32b00..00000000000 --- a/src/mongo/logger/tag_message_log_domain.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright 2014 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects - * for all of the code used other than as permitted herein. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you do not - * wish to do so, delete this exception statement from your version. If you - * delete this exception statement from all source files in the program, - * then also delete it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/logger/tag_message_log_domain.h" - -namespace mongo { -namespace logger { - - TagMessageLogDomain::TagMessageLogDomain() {} - - TagMessageLogDomain::~TagMessageLogDomain() {} - - bool TagMessageLogDomain::hasMinimumLogSeverity(LogTag tag) const { - return _settings.hasMinimumLogSeverity(tag); - } - - bool TagMessageLogDomain::shouldLog(LogSeverity severity) const { - return _settings.shouldLog(severity); - } - - bool TagMessageLogDomain::shouldLog(LogTag tag, LogSeverity severity) const { - return _settings.shouldLog(tag, severity); - } - - bool TagMessageLogDomain::shouldLog(LogTag tag1, LogTag tag2, LogSeverity severity) const { - return _settings.shouldLog(tag1, severity) || _settings.shouldLog(tag2, severity); - } - - bool TagMessageLogDomain::shouldLog(LogTag tag1, LogTag tag2, LogTag tag3, - LogSeverity severity) const { - return _settings.shouldLog(tag1, severity) || _settings.shouldLog(tag2, severity) || - _settings.shouldLog(tag3, severity); - } - - LogSeverity TagMessageLogDomain::getMinimumLogSeverity() const { - return _settings.getMinimumLogSeverity(LogTag::kDefault); - } - - LogSeverity TagMessageLogDomain::getMinimumLogSeverity(LogTag tag) const { - return _settings.getMinimumLogSeverity(tag); - } - - void TagMessageLogDomain::setMinimumLoggedSeverity(LogSeverity severity) { - _settings.setMinimumLoggedSeverity(LogTag::kDefault, severity); - } - - void TagMessageLogDomain::setMinimumLoggedSeverity(LogTag tag, LogSeverity severity) { - _settings.setMinimumLoggedSeverity(tag, severity); - } - - void TagMessageLogDomain::clearMinimumLoggedSeverity(LogTag tag) { - _settings.clearMinimumLoggedSeverity(tag); - } - -} // namespace logger -} // namespace mongo diff --git a/src/mongo/util/log.h b/src/mongo/util/log.h index a98b9b161f5..695eb8632c5 100644 --- a/src/mongo/util/log.h +++ b/src/mongo/util/log.h @@ -31,7 +31,7 @@ #include "mongo/base/status.h" #include "mongo/bson/util/builder.h" -#include "mongo/logger/log_tag.h" +#include "mongo/logger/log_component.h" #include "mongo/logger/logger.h" #include "mongo/logger/logstream_builder.h" #include "mongo/logger/tee.h" @@ -86,25 +86,29 @@ namespace logger { } -// MONGO_LOG uses log tag from MongoLogDefaultTag from current or global namespace. +// MONGO_LOG uses log component from MongoLogDefaultComponent from current or global namespace. #define MONGO_LOG(DLEVEL) \ - if (!(::mongo::logger::globalLogDomain())->shouldLog(MongoLogDefaultTag_tag, ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ + if (!(::mongo::logger::globalLogDomain())->shouldLog(MongoLogDefaultComponent_component, ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ else LogstreamBuilder(::mongo::logger::globalLogDomain(), getThreadName(), ::mongo::LogstreamBuilder::severityCast(DLEVEL)) #define LOG MONGO_LOG -#define MONGO_LOG_TAG(DLEVEL, TAG1) \ - if (!(::mongo::logger::globalLogDomain())->shouldLog((TAG1), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ +#define MONGO_LOG_COMPONENT(DLEVEL, COMPONENT1) \ + if (!(::mongo::logger::globalLogDomain())->shouldLog((COMPONENT1), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ else LogstreamBuilder(::mongo::logger::globalLogDomain(), getThreadName(), ::mongo::LogstreamBuilder::severityCast(DLEVEL)) -#define MONGO_LOG_TAG2(DLEVEL, TAG1, TAG2) \ - if (!(::mongo::logger::globalLogDomain())->shouldLog((TAG1), (TAG2), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ +#define MONGO_LOG_COMPONENT2(DLEVEL, COMPONENT1, COMPONENT2) \ + if (!(::mongo::logger::globalLogDomain())->shouldLog((COMPONENT1), (COMPONENT2), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ else LogstreamBuilder(::mongo::logger::globalLogDomain(), getThreadName(), ::mongo::LogstreamBuilder::severityCast(DLEVEL)) -#define MONGO_LOG_TAG3(DLEVEL, TAG1, TAG2, TAG3) \ - if (!(::mongo::logger::globalLogDomain())->shouldLog((TAG1), (TAG2), (TAG3), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ +#define MONGO_LOG_COMPONENT3(DLEVEL, COMPONENT1, COMPONENT2, COMPONENT3) \ + if (!(::mongo::logger::globalLogDomain())->shouldLog((COMPONENT1), (COMPONENT2), (COMPONENT3), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) {} \ else LogstreamBuilder(::mongo::logger::globalLogDomain(), getThreadName(), ::mongo::LogstreamBuilder::severityCast(DLEVEL)) +#define MONGO_LOG_TAG MONGO_LOG_COMPONENT +#define MONGO_LOG_TAG2 MONGO_LOG_COMPONENT2 +#define MONGO_LOG_TAG3 MONGO_LOG_COMPONENT3 + /** * Rotates the log files. Returns true if all logs rotate successfully. * @@ -143,22 +147,25 @@ namespace logger { } // namespace mongo /** - * Defines default log tag for MONGO_LOG. + * Defines default log component for MONGO_LOG. * Use this macro inside an implementation namespace or code block where debug messages * are logged using MONGO_LOG(). * * Note: Do not use more than once inside any namespace/code block. * Using static function instead of enum to support use inside function code block. */ -#define MONGO_LOG_DEFAULT_TAG_FILE(TAG) \ - static const ::mongo::logger::LogTag MongoLogDefaultTag_tag = (TAG); +#define MONGO_LOG_DEFAULT_COMPONENT_FILE(COMPONENT) \ + static const ::mongo::logger::LogComponent MongoLogDefaultComponent_component = (COMPONENT); /** - * MONGO_LOG_DEFAULT_TAG for local code block. + * MONGO_LOG_DEFAULT_COMPONENT for local code block. */ -#define MONGO_LOG_DEFAULT_TAG_LOCAL(TAG) \ - const ::mongo::logger::LogTag MongoLogDefaultTag_tag = (TAG); +#define MONGO_LOG_DEFAULT_COMPONENT_LOCAL(COMPONENT) \ + const ::mongo::logger::LogComponent MongoLogDefaultComponent_component = (COMPONENT); + +#define MONGO_LOG_DEFAULT_TAG_FILE MONGO_LOG_DEFAULT_COMPONENT_FILE +#define MONGO_LOG_DEFAULT_TAG_LOCAL MONGO_LOG_DEFAULT_COMPONENT_LOCAL -// Provide log tag in global scope so that MONGO_LOG will always have -// a valid tag. -const ::mongo::logger::LogTag MongoLogDefaultTag_tag = ::mongo::logger::LogTag::kDefault; +// Provide log component in global scope so that MONGO_LOG will always have a valid component. +const ::mongo::logger::LogComponent MongoLogDefaultComponent_component = + ::mongo::logger::LogComponent::kDefault; |