From b08b3ae8320d747f25da30f3fca939051707677c Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Fri, 27 Jun 2014 08:39:47 -0400 Subject: SERVER-5092 added server parameters for tag log levels --- src/mongo/db/commands/parameters.cpp | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/mongo') diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp index 87626d2cd32..479e56e3d96 100644 --- a/src/mongo/db/commands/parameters.cpp +++ b/src/mongo/db/commands/parameters.cpp @@ -32,6 +32,7 @@ #include +#include "mongo/base/init.h" #include "mongo/client/replica_set_monitor.h" #include "mongo/client/sasl_client_authenticate.h" #include "mongo/db/auth/authorization_manager.h" @@ -247,6 +248,60 @@ 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. + */ + class TagLogLevelSetting : public ServerParameter { + MONGO_DISALLOW_COPYING(TagLogLevelSetting); + public: + explicit TagLogLevelSetting(logger::LogTag tag) + : ServerParameter(ServerParameterSet::getGlobal(), + "logLevel_" + tag.getShortName()), + _tag(tag) {} + + virtual void append(OperationContext* txn, BSONObjBuilder& b, const std::string& name) { + if (!logger::globalLogDomain()->hasMinimumLogSeverity(_tag)) { + b << name << -1; + return; + } + b << name << logger::globalLogDomain()->getMinimumLogSeverity(_tag).toInt(); + } + + virtual Status set(const BSONElement& newValueElement) { + typedef logger::LogSeverity LogSeverity; + int newValue; + if (!newValueElement.coerce(&newValue)) + return Status(ErrorCodes::BadValue, mongoutils::str::stream() << + "Invalid value for logLevel: " << newValueElement); + return _setLogLevel(newValue); + } + + virtual Status setFromString(const std::string& str) { + typedef logger::LogSeverity LogSeverity; + int newValue; + Status status = parseNumberFromString(str, &newValue); + if (!status.isOK()) + return status; + return _setLogLevel(newValue); + return Status::OK(); + } + private: + Status _setLogLevel(int newValue) { + if (newValue < 0) { + logger::globalLogDomain()->clearMinimumLoggedSeverity(_tag); + return Status::OK(); + } + typedef logger::LogSeverity LogSeverity; + LogSeverity newSeverity = (newValue > 0) ? LogSeverity::Debug(newValue) : + LogSeverity::Log(); + logger::globalLogDomain()->setMinimumLoggedSeverity(_tag, newSeverity); + return Status::OK(); + } + logger::LogTag _tag; + }; + class SSLModeSetting : public ServerParameter { public: SSLModeSetting() : ServerParameter(ServerParameterSet::getGlobal(), "sslMode", @@ -421,5 +476,24 @@ namespace mongo { true); // allowedToChangeAtRuntime } + namespace { + // + // Command instances. + // Registers commands with the command system and make commands + // available to the client. + // + + MONGO_INITIALIZER_WITH_PREREQUISITES(SetupTagLogLevelSettings, + MONGO_NO_PREREQUISITES)(InitializerContext* context) { + for (int i = 0; i < int(logger::LogTag::kNumLogTags); ++i) { + logger::LogTag tag = static_cast(i); + if (tag == logger::LogTag::kDefault) { continue; } + new TagLogLevelSetting(tag); + } + + return Status::OK(); + } + + } // namespace } -- cgit v1.2.1