diff options
author | Shaun Verch <shaun.verch@mongodb.com> | 2014-03-27 20:11:11 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@mongodb.com> | 2014-03-28 13:46:54 -0400 |
commit | 41d6c151f40d40ef0673bb4e5e28d8e9c15e3cc0 (patch) | |
tree | 1f0db7646ef84b3f4eb30a0e6630f02a0d22a44c /src/mongo/db/server_options_helpers.cpp | |
parent | 9f0e88d0a4c00c125ce52d3954503dd1c91eae7c (diff) | |
download | mongo-41d6c151f40d40ef0673bb4e5e28d8e9c15e3cc0.tar.gz |
SERVER-13379 Canonicalize verbose and v options as systemLog.verbosity
Diffstat (limited to 'src/mongo/db/server_options_helpers.cpp')
-rw-r--r-- | src/mongo/db/server_options_helpers.cpp | 102 |
1 files changed, 56 insertions, 46 deletions
diff --git a/src/mongo/db/server_options_helpers.cpp b/src/mongo/db/server_options_helpers.cpp index c3285616a26..db9e31fe01b 100644 --- a/src/mongo/db/server_options_helpers.cpp +++ b/src/mongo/db/server_options_helpers.cpp @@ -140,13 +140,10 @@ namespace { // v=true | 1 // vv=true | 2 (etc.) // - // JSON Config Option | Resulting Verbosity + // YAML Config Option | Resulting Verbosity // _________________________________________ - // { "verbose" : "" } | 0 - // { "verbose" : "v" } | 1 - // { "verbose" : "vv" }| 2 (etc.) - // { "v" : true } | 1 - // { "vv" : true } | 2 (etc.) + // systemLog: | + // verbosity: 5 | 5 options->addOptionChaining("verbose", "verbose,v", moe::String, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)") .setImplicit(moe::Value(std::string("v"))) @@ -385,8 +382,21 @@ namespace { } Status validateServerOptions(const moe::Environment& params) { - // This function should contain custom validation that cannot be expressed as simple - // constraints on the options. + if (params.count("verbose")) { + std::string verbosity = params["verbose"].as<std::string>(); + + // Skip this for backwards compatibility. See SERVER-11471. + if (verbosity != "true") { + for (std::string::iterator iterator = verbosity.begin(); + iterator != verbosity.end(); iterator++) { + if (*iterator != 'v') { + return Status(ErrorCodes::BadValue, + "The \"verbose\" option string cannot contain any characters " + "other than \"v\""); + } + } + } + } return Status::OK(); } @@ -453,6 +463,42 @@ namespace { } } + // Handle both the "--verbose" string argument and the "-vvvv" arguments at the same time so + // that we ensure that we set the log level to the maximum of the options provided + int logLevel = -1; + for (std::string s = ""; s.length() <= 14; s.append("v")) { + if (!s.empty() && params->count(s)) { + logLevel = s.length(); + } + + if (params->count("verbose")) { + std::string verbosity; + params->get("verbose", &verbosity); + if (s == verbosity || + // Treat a verbosity of "true" the same as a single "v". See SERVER-11471. + (s == "v" && verbosity == "true")) { + logLevel = s.length(); + } + } + + // Remove all "v" options we have already handled + Status ret = params->remove(s); + if (!ret.isOK()) { + return ret; + } + } + + if (logLevel != -1) { + Status ret = params->set("systemLog.verbosity", moe::Value(logLevel)); + if (!ret.isOK()) { + return ret; + } + ret = params->remove("verbose"); + if (!ret.isOK()) { + return ret; + } + } + return Status::OK(); } @@ -485,53 +531,17 @@ namespace { "The net.http.port option is not currently supported"); } - if (params.count("verbose")) { - std::string verbosity = params["verbose"].as<std::string>(); - - // Skip this for backwards compatibility. See SERVER-11471. - if (verbosity != "true") { - for (std::string::iterator iterator = verbosity.begin(); - iterator != verbosity.end(); iterator++) { - if (*iterator != 'v') { - return Status(ErrorCodes::BadValue, - "The \"verbose\" option string cannot contain any characters " - "other than \"v\""); - } - } - } - } - - // Handle the JSON config file verbosity setting first so that it gets overriden by the - // setting on the command line if (params.count("systemLog.verbosity")) { int verbosity = params["systemLog.verbosity"].as<int>(); if (verbosity < 0) { + // This can only happen in YAML config return Status(ErrorCodes::BadValue, - "systemLog.verbosity in JSON Config cannot be negative"); + "systemLog.verbosity YAML Config cannot be negative"); } logger::globalLogDomain()->setMinimumLoggedSeverity( logger::LogSeverity::Debug(verbosity)); } - // Handle both the "--verbose" string argument and the "-vvvv" arguments at the same time so - // that we ensure that we set the log level to the maximum of the options provided - for (string s = ""; s.length() <= 14; s.append("v")) { - if (!s.empty() && params.count(s)) { - logger::globalLogDomain()->setMinimumLoggedSeverity( - logger::LogSeverity::Debug(s.length())); - } - - if (params.count("verbose")) { - std::string verbosity = params["verbose"].as<std::string>(); - if (s == verbosity || - // Treat a verbosity of "true" the same as a single "v". See SERVER-11471. - (s == "v" && verbosity == "true")) { - logger::globalLogDomain()->setMinimumLoggedSeverity( - logger::LogSeverity::Debug(s.length())); - } - } - } - if (params.count("enableExperimentalIndexStatsCmd")) { serverGlobalParams.experimental.indexStatsCmdEnabled = true; } |