summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2014-07-09 07:06:17 -0400
committerBenety Goh <benety@mongodb.com>2014-07-15 23:07:24 -0400
commit124b5aeda31a25a97e7f93fc1edb1565b7a2454a (patch)
tree30396ceab69c56d4d7b31e4beda9953f4f9004d8 /src/mongo
parent6f8e975b7a7ef18baf25281b206288a74deb5972 (diff)
downloadmongo-124b5aeda31a25a97e7f93fc1edb1565b7a2454a.tar.gz
SERVER-14416 added server parameter logComponentVerbosity.
This supports the use of BSON objects in querying/updating the log component hierarchy.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/parameters.cpp122
1 files changed, 121 insertions, 1 deletions
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index ff5ac1ef54c..69e34b173d6 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -28,11 +28,12 @@
* it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
#include <set>
#include "mongo/base/init.h"
+#include "mongo/bson/mutable/document.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/db/auth/authorization_manager.h"
@@ -44,6 +45,8 @@
#include "mongo/util/net/ssl_manager.h"
#include "mongo/util/net/ssl_options.h"
+using std::string;
+
namespace mongo {
namespace {
@@ -302,6 +305,123 @@ namespace mongo {
logger::LogComponent _component;
};
+ /**
+ * Log component verbosity.
+ * Log levels of log component hierarchy.
+ * Negative value for a log component means the default log level will be used.
+ */
+ class LogComponentVerbositySetting : public ServerParameter {
+ MONGO_DISALLOW_COPYING(LogComponentVerbositySetting);
+ public:
+ LogComponentVerbositySetting()
+ : ServerParameter(ServerParameterSet::getGlobal(), "logComponentVerbosity") {}
+
+ virtual void append(OperationContext* txn, BSONObjBuilder& b,
+ const std::string& name) {
+ mutablebson::Document doc;
+ for (int i = 0; i < int(logger::LogComponent::kNumLogComponents); ++i) {
+ logger::LogComponent component = static_cast<logger::LogComponent::Value>(i);
+ mutablebson::Element element = doc.makeElementObject(component.getShortName());
+ if (logger::globalLogDomain()->hasMinimumLogSeverity(component)) {
+ logger::LogSeverity severity =
+ logger::globalLogDomain()->getMinimumLogSeverity(component);
+ element.appendInt("verbosity", severity.toInt());
+ }
+ else {
+ element.appendInt("verbosity", -1);
+ }
+ mutablebson::Element parentElement = _getParentElement(doc, component);
+ parentElement.pushBack(element);
+ }
+ const string defaultLogComponentName =
+ logger::LogComponent(logger::LogComponent::kDefault).getShortName();
+ b << name << doc.getObject().getObjectField(defaultLogComponentName);
+ }
+
+ virtual Status set(const BSONElement& newValueElement) {
+ if (!newValueElement.isABSONObj()) {
+ return Status(ErrorCodes::TypeMismatch, mongoutils::str::stream() <<
+ "log component verbosity is not a BSON object: " <<
+ newValueElement);
+ }
+ return _set(newValueElement.Obj());
+ }
+
+ virtual Status setFromString(const std::string& str) {
+ try {
+ return _set(mongo::fromjson(str));
+ }
+ catch (const DBException& ex) {
+ return ex.toStatus();
+ }
+ }
+
+ private:
+ /**
+ * Updates component hierarchy log levels.
+ *
+ * BSON Format:
+ * {
+ * verbosity: 4, <-- maps to 'default' log component.
+ * componentA: {
+ * verbosity: 2, <-- sets componentA's log level to 2.
+ * componentB: {
+ * verbosity: 1, <-- sets componentA.componentB's log level to 1.
+ * }
+ * componentC: {
+ * verbosity: -1, <-- clears componentA.componentC's log level so that
+ * its final loglevel will be inherited from componentA.
+ * }
+ * }
+ * }
+ *
+ * Ignore elements in BSON object that do not map to a log component's dotted
+ * name.
+ */
+ Status _set(const BSONObj& obj) const {
+ for (int i = 0; i < int(logger::LogComponent::kNumLogComponents); ++i) {
+ logger::LogComponent component = static_cast<logger::LogComponent::Value>(i);
+ const string fieldName = component == logger::LogComponent::kDefault ?
+ "verbosity" : (component.getDottedName() + ".verbosity");
+ BSONElement element = obj.getFieldDotted(fieldName);
+ if (element.eoo()) {
+ continue;
+ }
+ int newValue;
+ if (!element.coerce(&newValue)) {
+ return Status(ErrorCodes::TypeMismatch, mongoutils::str::stream() <<
+ "Invalid value for " << component.getDottedName() <<
+ " logLevel: " << element);
+ }
+ // Negative value means to clear log level of component.
+ if (newValue < 0) {
+ logger::globalLogDomain()->clearMinimumLoggedSeverity(component);
+ return Status::OK();
+ }
+ // Convert non-negative value to Log()/Debug(N).
+ typedef logger::LogSeverity LogSeverity;
+ LogSeverity newSeverity = (newValue > 0) ? LogSeverity::Debug(newValue) :
+ LogSeverity::Log();
+ logger::globalLogDomain()->setMinimumLoggedSeverity(component, newSeverity);
+ }
+
+ return Status::OK();
+ }
+
+ /**
+ * Search document for element corresponding to log component's parent.
+ */
+ static mutablebson::Element _getParentElement(mutablebson::Document& doc,
+ logger::LogComponent component) {
+ if (component == logger::LogComponent::kDefault) {
+ return doc.root();
+ }
+ logger::LogComponent parentComponent = component.parent();
+ mutablebson::Element grandParentElement = _getParentElement(doc, parentComponent);
+ return grandParentElement.findFirstChildNamed(parentComponent.getShortName());
+ }
+ } logComponentVerbositySetting;
+
class SSLModeSetting : public ServerParameter {
public:
SSLModeSetting() : ServerParameter(ServerParameterSet::getGlobal(), "sslMode",