diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2020-03-22 20:33:03 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-23 00:49:46 +0000 |
commit | 79a8452b2a813b796059e5eab6c18f685283ce08 (patch) | |
tree | bd5012bda9b1561f741c46bfadc7363837ad3d0e /src/mongo/db | |
parent | c91a2f5932ac08ca28b25ce11b8ac4949552e271 (diff) | |
download | mongo-79a8452b2a813b796059e5eab6c18f685283ce08.tar.gz |
Revert "SERVER-46765 fix '--version' & '--sysinfo', which use kPlain logging"
This reverts commit cddfeb0c7cb137d46b14da18a7cfd4905bfab87f.
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/db.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/log_process_details.cpp | 34 | ||||
-rw-r--r-- | src/mongo/db/log_process_details.h | 7 | ||||
-rw-r--r-- | src/mongo/db/mongod_options.cpp | 35 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.h | 7 |
6 files changed, 39 insertions, 58 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 84a2c053edb..0615dbf351a 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -326,7 +326,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) { VersionInfoInterface::instance().logTargetMinOS(); #endif - logProcessDetails(nullptr); + logProcessDetails(); serviceContext->setServiceEntryPoint(std::make_unique<ServiceEntryPointMongod>(serviceContext)); diff --git a/src/mongo/db/log_process_details.cpp b/src/mongo/db/log_process_details.cpp index 312bd8ff282..9d43247991a 100644 --- a/src/mongo/db/log_process_details.cpp +++ b/src/mongo/db/log_process_details.cpp @@ -33,11 +33,6 @@ #include "mongo/db/log_process_details.h" -#include <ostream> - -#include "mongo/bson/bsonobj.h" -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/bson/json.h" #include "mongo/db/repl/repl_set_config.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/server_options.h" @@ -49,35 +44,26 @@ namespace mongo { -namespace { - bool is32bit() { return (sizeof(int*) == 4); } -} // namespace - -void logProcessDetails(std::ostream* os) { +void logProcessDetails() { auto&& vii = VersionInfoInterface::instance(); + vii.logBuildInfo(); + + ProcessInfo p; + LOGV2( + 51765, "Operating system", "name"_attr = p.getOsName(), "version"_attr = p.getOsVersion()); + if (ProcessInfo::getMemSizeMB() < ProcessInfo::getSystemMemSizeMB()) { LOGV2_WARNING(20720, "Available memory is less than system memory", "availableMemSizeMB"_attr = ProcessInfo::getMemSizeMB(), "systemMemSizeMB"_attr = ProcessInfo::getSystemMemSizeMB()); } - auto osInfo = BSONObjBuilder() - .append("name", ProcessInfo::getOsName()) - .append("version", ProcessInfo::getOsVersion()) - .obj(); - vii.logBuildInfo(os); - if (os) { - *os << format(FMT_STRING("Operating System: {}"), - tojson(osInfo, ExtendedRelaxedV2_0_0, true)) - << std::endl; - printCommandLineOpts(os); - } else { - LOGV2(51765, "Operating System", "os"_attr = osInfo); - } + + printCommandLineOpts(); } void logProcessDetailsForLogRotate(ServiceContext* serviceContext) { @@ -103,7 +89,7 @@ void logProcessDetailsForLogRotate(ServiceContext* serviceContext) { } } - logProcessDetails(nullptr); + logProcessDetails(); } } // namespace mongo diff --git a/src/mongo/db/log_process_details.h b/src/mongo/db/log_process_details.h index 677fea672bb..d74fcc5fe52 100644 --- a/src/mongo/db/log_process_details.h +++ b/src/mongo/db/log_process_details.h @@ -29,17 +29,14 @@ #pragma once -#include <iosfwd> - namespace mongo { class ServiceContext; /** - * Writes useful information about the running process. - * If `os` is nonnull, print to it, else to LOGV2. + * Writes useful information about the running process to the diagnostic log on startup. */ -void logProcessDetails(std::ostream* os); +void logProcessDetails(); /** * Writes useful information about the running process to diagnostic log diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 78a8befe022..c1926b20762 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -101,20 +101,23 @@ void printMongodHelp(const moe::OptionSection& options) { }; namespace { - -void appendSysInfo(BSONObjBuilder* obj) { - auto o = BSONObjBuilder(obj->subobjStart("sysinfo")); +void sysRuntimeInfo() { #if defined(_SC_PAGE_SIZE) - o.append("_SC_PAGE_SIZE", (long long)sysconf(_SC_PAGE_SIZE)); + LOGV2(20873, + " page size: {int_sysconf_SC_PAGE_SIZE}", + "int_sysconf_SC_PAGE_SIZE"_attr = (int)sysconf(_SC_PAGE_SIZE)); #endif #if defined(_SC_PHYS_PAGES) - o.append("_SC_PHYS_PAGES", (long long)sysconf(_SC_PHYS_PAGES)); + LOGV2(20874, + " _SC_PHYS_PAGES: {sysconf_SC_PHYS_PAGES}", + "sysconf_SC_PHYS_PAGES"_attr = sysconf(_SC_PHYS_PAGES)); #endif #if defined(_SC_AVPHYS_PAGES) - o.append("_SC_AVPHYS_PAGES", (long long)sysconf(_SC_AVPHYS_PAGES)); + LOGV2(20875, + " _SC_AVPHYS_PAGES: {sysconf_SC_AVPHYS_PAGES}", + "sysconf_SC_AVPHYS_PAGES"_attr = sysconf(_SC_AVPHYS_PAGES)); #endif } - } // namespace bool handlePreValidationMongodOptions(const moe::Environment& params, @@ -123,16 +126,24 @@ bool handlePreValidationMongodOptions(const moe::Environment& params, printMongodHelp(moe::startupOptions); return false; } + + auto setPlainLogFormat = []() { + auto& globalDomain = logv2::LogManager::global().getGlobalDomainInternal(); + logv2::LogDomainGlobal::ConfigurationOptions config = globalDomain.config(); + config.format = logv2::LogFormat::kPlain; + invariant(globalDomain.configure(config).isOK()); + }; + if (params.count("version") && params["version"].as<bool>() == true) { + setPlainLogFormat(); auto&& vii = VersionInfoInterface::instance(); - std::cout << mongodVersion(vii) << std::endl; - vii.logBuildInfo(&std::cout); + LOGV2(20876, "{mongodVersion_vii}", "mongodVersion_vii"_attr = mongodVersion(vii)); + vii.logBuildInfo(); return false; } if (params.count("sysinfo") && params["sysinfo"].as<bool>() == true) { - BSONObjBuilder obj; - appendSysInfo(&obj); - std::cout << tojson(obj.done(), ExtendedRelaxedV2_0_0, true) << std::endl; + setPlainLogFormat(); + sysRuntimeInfo(); return false; } diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp index 0d237dfe7bd..878fa85a40f 100644 --- a/src/mongo/db/server_options_server_helpers.cpp +++ b/src/mongo/db/server_options_server_helpers.cpp @@ -37,12 +37,10 @@ #include <boost/algorithm/string/trim.hpp> #include <boost/filesystem.hpp> #include <boost/filesystem/operations.hpp> -#include <fmt/format.h> #include <ios> #include <iostream> #include "mongo/base/status.h" -#include "mongo/bson/json.h" #include "mongo/bson/util/builder.h" #include "mongo/config.h" #include "mongo/db/server_options.h" @@ -115,14 +113,8 @@ Status setParsedOpts(const moe::Environment& params) { } } // namespace -void printCommandLineOpts(std::ostream* os) { - if (os) { - *os << format(FMT_STRING("Options set by command line: {}"), - tojson(serverGlobalParams.parsedOpts, ExtendedRelaxedV2_0_0, true)) - << std::endl; - } else { - LOGV2(21951, "Options set by command line", "options"_attr = serverGlobalParams.parsedOpts); - } +void printCommandLineOpts() { + LOGV2(21951, "Options set by command line", "options"_attr = serverGlobalParams.parsedOpts); } Status validateServerOptions(const moe::Environment& params) { diff --git a/src/mongo/db/server_options_server_helpers.h b/src/mongo/db/server_options_server_helpers.h index 5a243ab5dee..51a59315554 100644 --- a/src/mongo/db/server_options_server_helpers.h +++ b/src/mongo/db/server_options_server_helpers.h @@ -29,8 +29,6 @@ #pragma once -#include <iosfwd> - #include "mongo/base/status.h" #include "mongo/util/options_parser/environment.h" #include "mongo/util/options_parser/option_section.h" @@ -68,9 +66,6 @@ Status setupServerOptions(const std::vector<std::string>& args); */ Status storeServerOptions(const optionenvironment::Environment& params); -/** - * Write to `os`, or to LOGV2 if null. - */ -void printCommandLineOpts(std::ostream* os); +void printCommandLineOpts(); } // namespace mongo |