summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-04-14 16:45:29 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-15 22:09:40 +0000
commitda349337d17dfa6bf5e92edac92045fab84e1742 (patch)
tree7bb83f22696f506ccde7f336939acdc8102678c7 /src/mongo
parent31858ad493d65e90eb5447427bf11e317af9b939 (diff)
downloadmongo-da349337d17dfa6bf5e92edac92045fab84e1742.tar.gz
SERVER-47578 Delete util/log.h and remove use of logv1 to logv2 appender
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/db/commands/generic_servers.cpp12
-rw-r--r--src/mongo/db/curop.cpp1
-rw-r--r--src/mongo/db/initialize_server_global_state.cpp124
-rw-r--r--src/mongo/db/logical_session_cache_impl.cpp2
-rw-r--r--src/mongo/db/record_id.h6
-rw-r--r--src/mongo/db/repl/vote_requester.cpp1
-rw-r--r--src/mongo/dbtests/jstests.cpp2
-rw-r--r--src/mongo/executor/connection_pool.cpp2
-rw-r--r--src/mongo/logger/log_component_settings_test.cpp2
-rw-r--r--src/mongo/logger/log_function_test.cpp2
-rw-r--r--src/mongo/logger/log_manager.cpp13
-rw-r--r--src/mongo/logger/log_test.cpp2
-rw-r--r--src/mongo/logger/log_test.h70
-rw-r--r--src/mongo/logger/log_test_util.h (renamed from src/mongo/util/log.h)27
-rw-r--r--src/mongo/logv2/log_options.h3
-rw-r--r--src/mongo/logv2/logv2_bm.cpp112
-rw-r--r--src/mongo/logv2/redaction_test.cpp1
-rw-r--r--src/mongo/shell/dbshell.cpp63
-rw-r--r--src/mongo/util/log.cpp82
-rw-r--r--src/mongo/util/log_global_settings.h11
-rw-r--r--src/mongo/util/signal_handlers_synchronous.cpp14
22 files changed, 90 insertions, 463 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 552183bea8f..82f91bf7764 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -153,7 +153,6 @@ baseEnv.Library(
'util/file.cpp',
'util/hex.cpp',
'util/itoa.cpp',
- 'util/log.cpp',
'util/platform_init.cpp',
'util/shell_exec.cpp',
'util/signal_handlers_synchronous.cpp',
diff --git a/src/mongo/db/commands/generic_servers.cpp b/src/mongo/db/commands/generic_servers.cpp
index c896cec3c1b..7cccc042bc7 100644
--- a/src/mongo/db/commands/generic_servers.cpp
+++ b/src/mongo/db/commands/generic_servers.cpp
@@ -232,10 +232,7 @@ public:
const BSONObj& cmdObj,
std::string& errmsg,
BSONObjBuilder& result) override {
- if (logV2Enabled()) {
- return errmsgRunImpl<logv2::RamLog>(opCtx, dbname, cmdObj, errmsg, result);
- }
- return errmsgRunImpl<RamLog>(opCtx, dbname, cmdObj, errmsg, result);
+ return errmsgRunImpl<logv2::RamLog>(opCtx, dbname, cmdObj, errmsg, result);
}
template <typename RamLogType>
@@ -321,11 +318,8 @@ public:
invariant(ramlog);
ramlog->clear();
};
- if (logV2Enabled()) {
- clearRamlog(logv2::RamLog::getIfExists(logName));
- } else {
- clearRamlog(RamLog::getIfExists(logName));
- }
+ clearRamlog(logv2::RamLog::getIfExists(logName));
+
return true;
}
};
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index 429d870f33d..5c2afc9d349 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -54,7 +54,6 @@
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
#include "mongo/rpc/metadata/impersonated_user_metadata.h"
#include "mongo/util/hex.h"
-#include "mongo/util/log.h"
#include "mongo/util/log_with_sampling.h"
#include "mongo/util/net/socket_utils.h"
#include "mongo/util/str.h"
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp
index f11bc05257f..f4cf3fb9f19 100644
--- a/src/mongo/db/initialize_server_global_state.cpp
+++ b/src/mongo/db/initialize_server_global_state.cpp
@@ -52,7 +52,6 @@
#include "mongo/db/server_options.h"
#include "mongo/logger/console_appender.h"
#include "mongo/logger/logger.h"
-#include "mongo/logger/logv2_appender.h"
#include "mongo/logger/message_event.h"
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logger/ramlog.h"
@@ -311,7 +310,6 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
using logger::StatusWithRotatableFileWriter;
// Hook up this global into our logging encoder
- LogManager* manager = logger::globalLogManager();
auto& lv2Manager = logv2::LogManager::global();
logv2::LogDomainGlobal::ConfigurationOptions lv2Config;
MessageEventDetailsEncoder::setMaxLogSizeKBSource(gMaxLogAttributeSizeKB);
@@ -323,33 +321,9 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
return Status(ErrorCodes::InternalError,
"Syslog requested in Windows build; command line processor logic error");
#else
- std::unique_ptr<logger::Appender<MessageEventEphemeral>> appender;
- std::unique_ptr<logger::Appender<MessageEventEphemeral>> javascriptAppender;
-
- if (logV2Enabled()) {
- appender = std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
- &(lv2Manager.getGlobalDomain()), true);
- javascriptAppender = std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
- &(lv2Manager.getGlobalDomain()), true);
-
- lv2Config.consoleEnabled = false;
- lv2Config.syslogEnabled = true;
- lv2Config.syslogFacility = serverGlobalParams.syslogFacility;
- } else {
- using logger::SyslogAppender;
- StringBuilder sb;
- sb << serverGlobalParams.binaryName << "." << serverGlobalParams.port;
- openlog(
- strdup(sb.str().c_str()), LOG_PID | LOG_CONS, serverGlobalParams.syslogFacility);
- appender = std::make_unique<SyslogAppender<MessageEventEphemeral>>(
- std::make_unique<MessageEventDetailsEncoder>());
- javascriptAppender = std::make_unique<SyslogAppender<MessageEventEphemeral>>(
- std::make_unique<MessageEventDetailsEncoder>());
- }
- manager->getGlobalDomain()->clearAppenders();
- manager->getGlobalDomain()->attachAppender(std::move(appender));
- manager->getNamedDomain("plainShellOutput")->attachAppender(std::move(javascriptAppender));
-
+ lv2Config.consoleEnabled = false;
+ lv2Config.syslogEnabled = true;
+ lv2Config.syslogFacility = serverGlobalParams.syslogFacility;
#endif // defined(_WIN32)
} else if (!serverGlobalParams.logpath.empty()) {
fassert(16448, !serverGlobalParams.logWithSyslog);
@@ -395,83 +369,27 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
}
}
- std::unique_ptr<logger::Appender<MessageEventEphemeral>> appender;
- std::unique_ptr<logger::Appender<MessageEventEphemeral>> javascriptAppender;
-
- if (logV2Enabled()) {
-
- appender = std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
- &(lv2Manager.getGlobalDomain()), true);
- javascriptAppender = std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
- &(lv2Manager.getGlobalDomain()), true);
-
- lv2Config.consoleEnabled = false;
- lv2Config.fileEnabled = true;
- lv2Config.filePath = absoluteLogpath;
- lv2Config.fileRotationMode = serverGlobalParams.logRenameOnRotate
- ? logv2::LogDomainGlobal::ConfigurationOptions::RotationMode::kRename
- : logv2::LogDomainGlobal::ConfigurationOptions::RotationMode::kReopen;
- lv2Config.fileOpenMode = serverGlobalParams.logAppend
- ? logv2::LogDomainGlobal::ConfigurationOptions::OpenMode::kAppend
- : logv2::LogDomainGlobal::ConfigurationOptions::OpenMode::kTruncate;
-
- if (serverGlobalParams.logAppend && exists) {
- writeServerRestartedAfterLogConfig = true;
- }
-
- } else {
- StatusWithRotatableFileWriter writer = logger::globalRotatableFileManager()->openFile(
- absoluteLogpath, serverGlobalParams.logAppend);
- if (!writer.isOK()) {
- return writer.getStatus();
- }
- appender = std::make_unique<RotatableFileAppender<MessageEventEphemeral>>(
- std::make_unique<MessageEventDetailsEncoder>(), writer.getValue());
- javascriptAppender = std::make_unique<RotatableFileAppender<MessageEventEphemeral>>(
- std::make_unique<MessageEventDetailsEncoder>(), writer.getValue());
- if (serverGlobalParams.logAppend && exists) {
- LOGV2_WARNING_OPTIONS(
- 20699, {logv2::LogTag::kStartupWarnings}, "***** SERVER RESTARTED *****");
- Status status = logger::RotatableFileWriter::Use(writer.getValue()).status();
- if (!status.isOK())
- return status;
- }
- }
-
- manager->getGlobalDomain()->clearAppenders();
- manager->getGlobalDomain()->attachAppender(std::move(appender));
- manager->getNamedDomain("plainShellOutput")->attachAppender(std::move(javascriptAppender));
-
- } else {
- if (logV2Enabled()) {
- manager->getGlobalDomain()->clearAppenders();
- manager->getGlobalDomain()->attachAppender(
- std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
- &(lv2Manager.getGlobalDomain()), true));
- manager->getNamedDomain("plainShellOutput")
- ->attachAppender(std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
- &(lv2Manager.getGlobalDomain()), true));
- } else {
- logger::globalLogManager()
- ->getNamedDomain("plainShellOutput")
- ->attachAppender(std::make_unique<logger::ConsoleAppender<MessageEventEphemeral>>(
- std::make_unique<MessageEventDetailsEncoder>()));
+ lv2Config.consoleEnabled = false;
+ lv2Config.fileEnabled = true;
+ lv2Config.filePath = absoluteLogpath;
+ lv2Config.fileRotationMode = serverGlobalParams.logRenameOnRotate
+ ? logv2::LogDomainGlobal::ConfigurationOptions::RotationMode::kRename
+ : logv2::LogDomainGlobal::ConfigurationOptions::RotationMode::kReopen;
+ lv2Config.fileOpenMode = serverGlobalParams.logAppend
+ ? logv2::LogDomainGlobal::ConfigurationOptions::OpenMode::kAppend
+ : logv2::LogDomainGlobal::ConfigurationOptions::OpenMode::kTruncate;
+
+ if (serverGlobalParams.logAppend && exists) {
+ writeServerRestartedAfterLogConfig = true;
}
}
- if (!logV2Enabled()) {
- logger::globalLogDomain()->attachAppender(
- std::make_unique<RamLogAppender>(RamLog::get("global")));
- }
-
- if (logV2Enabled()) {
- lv2Config.timestampFormat = serverGlobalParams.logTimestampFormat;
- Status result = lv2Manager.getGlobalDomainInternal().configure(lv2Config);
- if (result.isOK() && writeServerRestartedAfterLogConfig)
- LOGV2_WARNING_OPTIONS(
- 20698, {logv2::LogTag::kStartupWarnings}, "***** SERVER RESTARTED *****");
- return result;
- }
+ lv2Config.timestampFormat = serverGlobalParams.logTimestampFormat;
+ Status result = lv2Manager.getGlobalDomainInternal().configure(lv2Config);
+ if (result.isOK() && writeServerRestartedAfterLogConfig)
+ LOGV2_WARNING_OPTIONS(
+ 20698, {logv2::LogTag::kStartupWarnings}, "***** SERVER RESTARTED *****");
+ return result;
return Status::OK();
}
diff --git a/src/mongo/db/logical_session_cache_impl.cpp b/src/mongo/db/logical_session_cache_impl.cpp
index d112ac42dda..c82d4451031 100644
--- a/src/mongo/db/logical_session_cache_impl.cpp
+++ b/src/mongo/db/logical_session_cache_impl.cpp
@@ -38,10 +38,10 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/service_context.h"
+#include "mongo/logger/log_severity_limiter.h"
#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/util/duration.h"
-#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
namespace mongo {
diff --git a/src/mongo/db/record_id.h b/src/mongo/db/record_id.h
index 42ab3062033..5ec5f51823f 100644
--- a/src/mongo/db/record_id.h
+++ b/src/mongo/db/record_id.h
@@ -202,10 +202,4 @@ inline std::ostream& operator<<(std::ostream& stream, const boost::optional<Reco
return stream << "RecordId(" << (id ? id.get().repr() : 0) << ')';
}
-inline logger::LogstreamBuilderDeprecated& operator<<(logger::LogstreamBuilderDeprecated& stream,
- const RecordId& id) {
- stream.stream() << id;
- return stream;
-}
-
} // namespace mongo
diff --git a/src/mongo/db/repl/vote_requester.cpp b/src/mongo/db/repl/vote_requester.cpp
index 561857a79ab..b1b51979a5c 100644
--- a/src/mongo/db/repl/vote_requester.cpp
+++ b/src/mongo/db/repl/vote_requester.cpp
@@ -41,7 +41,6 @@
#include "mongo/db/repl/scatter_gather_runner.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
-#include "mongo/util/log.h"
namespace mongo {
namespace repl {
diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp
index 5efcb146d5e..7955260d03d 100644
--- a/src/mongo/dbtests/jstests.cpp
+++ b/src/mongo/dbtests/jstests.cpp
@@ -40,12 +40,12 @@
#include "mongo/db/hasher.h"
#include "mongo/db/json.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/logger/logger.h"
#include "mongo/platform/decimal128.h"
#include "mongo/scripting/engine.h"
#include "mongo/shell/shell_utils.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/future.h"
-#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
#include "mongo/util/timer.h"
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp
index 2b4492fbba4..1594e57bdef 100644
--- a/src/mongo/executor/connection_pool.cpp
+++ b/src/mongo/executor/connection_pool.cpp
@@ -41,12 +41,12 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/executor/connection_pool_stats.h"
#include "mongo/executor/remote_command_request.h"
+#include "mongo/logger/log_severity_limiter.h"
#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/destructor_guard.h"
#include "mongo/util/hierarchical_acquisition.h"
-#include "mongo/util/log.h"
#include "mongo/util/lru_cache.h"
#include "mongo/util/scopeguard.h"
diff --git a/src/mongo/logger/log_component_settings_test.cpp b/src/mongo/logger/log_component_settings_test.cpp
index 38b1cf8274d..51d2d622586 100644
--- a/src/mongo/logger/log_component_settings_test.cpp
+++ b/src/mongo/logger/log_component_settings_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/logger/log_component.h"
diff --git a/src/mongo/logger/log_function_test.cpp b/src/mongo/logger/log_function_test.cpp
index d2acdba4e4f..a42818fa4a0 100644
--- a/src/mongo/logger/log_function_test.cpp
+++ b/src/mongo/logger/log_function_test.cpp
@@ -40,9 +40,9 @@
#include "mongo/logger/appender.h"
#include "mongo/logger/encoder.h"
#include "mongo/logger/log_component.h"
+#include "mongo/logger/log_test_util.h"
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logv2/text_formatter.h"
-#include "mongo/util/log.h"
#include "mongo/util/str.h"
using namespace mongo::logger;
diff --git a/src/mongo/logger/log_manager.cpp b/src/mongo/logger/log_manager.cpp
index 48eb660324f..3e04e5bd5bb 100644
--- a/src/mongo/logger/log_manager.cpp
+++ b/src/mongo/logger/log_manager.cpp
@@ -37,7 +37,6 @@
#include "mongo/logger/logv2_appender.h"
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logv2/log_domain_global.h"
-#include "mongo/util/log.h"
namespace mongo {
namespace logger {
@@ -68,15 +67,9 @@ void LogManager::detachDefaultConsoleAppender() {
void LogManager::reattachDefaultConsoleAppender() {
invariant(!_defaultAppender);
- if (logV2Enabled()) {
- _defaultAppender = _globalDomain.attachAppender(
- std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
- &logv2::LogManager::global().getGlobalDomain(), false));
- } else {
- _defaultAppender =
- _globalDomain.attachAppender(std::make_unique<ConsoleAppender<MessageEventEphemeral>>(
- std::make_unique<MessageEventDetailsEncoder>()));
- }
+ _defaultAppender =
+ _globalDomain.attachAppender(std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
+ &logv2::LogManager::global().getGlobalDomain(), false));
}
bool LogManager::isDefaultConsoleAppenderAttached() const {
diff --git a/src/mongo/logger/log_test.cpp b/src/mongo/logger/log_test.cpp
index a314450dbbe..464f3583a8b 100644
--- a/src/mongo/logger/log_test.cpp
+++ b/src/mongo/logger/log_test.cpp
@@ -41,6 +41,7 @@
#include "mongo/logger/encoder.h"
#include "mongo/logger/log_component.h"
#include "mongo/logger/log_component_settings.h"
+#include "mongo/logger/log_test_util.h"
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logger/message_log_domain.h"
#include "mongo/logger/rotatable_file_appender.h"
@@ -50,7 +51,6 @@
#include "mongo/platform/compiler.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/concurrency/thread_name.h"
-#include "mongo/util/log.h"
#include "mongo/util/str.h"
using namespace mongo::logger;
diff --git a/src/mongo/logger/log_test.h b/src/mongo/logger/log_test.h
index 3fd731a437c..6a405052e15 100644
--- a/src/mongo/logger/log_test.h
+++ b/src/mongo/logger/log_test.h
@@ -51,50 +51,35 @@
namespace mongo {
inline logger::LogSeverity getMinimumLogSeverity() {
- if (logV2Enabled())
- return logSeverityV2toV1(
- logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(
- mongo::logv2::LogComponent::kDefault));
- return logger::globalLogDomain()->getMinimumLogSeverity();
+ return logSeverityV2toV1(logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(
+ mongo::logv2::LogComponent::kDefault));
}
inline logger::LogSeverity getMinimumLogSeverity(logger::LogComponent component) {
- if (logV2Enabled())
- return logSeverityV2toV1(
- logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(
- logComponentV1toV2(component)));
- return logger::globalLogDomain()->getMinimumLogSeverity(component);
+ return logSeverityV2toV1(logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(
+ logComponentV1toV2(component)));
}
inline void setMinimumLoggedSeverity(logger::LogSeverity severity) {
- if (logV2Enabled())
- return logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
- mongo::logv2::LogComponent::kDefault, mongo::logSeverityV1toV2(severity));
- logger::globalLogDomain()->setMinimumLoggedSeverity(severity);
+ return logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, mongo::logSeverityV1toV2(severity));
}
inline void setMinimumLoggedSeverity(logger::LogComponent component, logger::LogSeverity severity) {
- if (logV2Enabled())
- return logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
- logComponentV1toV2(component), mongo::logSeverityV1toV2(severity));
- logger::globalLogDomain()->setMinimumLoggedSeverity(component, severity);
+ return logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ logComponentV1toV2(component), mongo::logSeverityV1toV2(severity));
}
inline void clearMinimumLoggedSeverity(logger::LogComponent component) {
- if (logV2Enabled())
- return logv2::LogManager::global().getGlobalSettings().clearMinimumLoggedSeverity(
- logComponentV1toV2(component));
- logger::globalLogDomain()->clearMinimumLoggedSeverity(component);
+ return logv2::LogManager::global().getGlobalSettings().clearMinimumLoggedSeverity(
+ logComponentV1toV2(component));
}
inline bool hasMinimumLogSeverity(logger::LogComponent component) {
- if (logV2Enabled())
- return logv2::LogManager::global().getGlobalSettings().hasMinimumLogSeverity(
- logComponentV1toV2(component));
- return logger::globalLogDomain()->hasMinimumLogSeverity(component);
+ return logv2::LogManager::global().getGlobalSettings().hasMinimumLogSeverity(
+ logComponentV1toV2(component));
}
-
namespace logger {
@@ -108,30 +93,23 @@ class LogTest : public unittest::Test {
public:
LogTest() : _severityOld(getMinimumLogSeverity()) {
globalLogDomain()->clearAppenders();
- if (logV2Enabled()) {
- _appenderHandle = globalLogDomain()->attachAppender(
- std::make_unique<LogV2Appender<MessageEventEphemeral>>(
- &logv2::LogManager::global().getGlobalDomain(), true));
-
- if (!_captureSink) {
- _captureSink = logv2::LogCaptureBackend::create(_logLines);
- _captureSink->set_filter(logv2::ComponentSettingsFilter(
- logv2::LogManager::global().getGlobalDomain(),
- logv2::LogManager::global().getGlobalSettings()));
- _captureSink->set_formatter(LOGV2Formatter());
- }
- boost::log::core::get()->add_sink(_captureSink);
- } else {
- _appenderHandle =
- globalLogDomain()->attachAppender(std::make_unique<LogTestAppender>(this));
+ _appenderHandle = globalLogDomain()->attachAppender(
+ std::make_unique<LogV2Appender<MessageEventEphemeral>>(
+ &logv2::LogManager::global().getGlobalDomain(), true));
+
+ if (!_captureSink) {
+ _captureSink = logv2::LogCaptureBackend::create(_logLines);
+ _captureSink->set_filter(
+ logv2::ComponentSettingsFilter(logv2::LogManager::global().getGlobalDomain(),
+ logv2::LogManager::global().getGlobalSettings()));
+ _captureSink->set_formatter(LOGV2Formatter());
}
+ boost::log::core::get()->add_sink(_captureSink);
}
virtual ~LogTest() {
globalLogDomain()->detachAppender(_appenderHandle);
- if (logV2Enabled()) {
- boost::log::core::get()->remove_sink(_captureSink);
- }
+ boost::log::core::get()->remove_sink(_captureSink);
setMinimumLoggedSeverity(_severityOld);
}
diff --git a/src/mongo/util/log.h b/src/mongo/logger/log_test_util.h
index 9dec9f07488..c13ff7489ef 100644
--- a/src/mongo/util/log.h
+++ b/src/mongo/logger/log_test_util.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018-present MongoDB, Inc.
+ * Copyright (C) 2020-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
@@ -38,34 +38,21 @@
#if defined(MONGO_UTIL_LOG_H_)
#error \
- "This may occur when log.h is included in a header. " \
+ "This may occur when log_test_util.h is included in a header. " \
"Please check your #include's."
#else // MONGO_UTIL_LOG_H_
#define MONGO_UTIL_LOG_H_
-#include "mongo/base/status.h"
-#include "mongo/bson/util/builder.h"
-#include "mongo/db/server_options.h"
#include "mongo/logger/log_component.h"
#include "mongo/logger/log_severity_limiter.h"
#include "mongo/logger/logger.h"
#include "mongo/logger/logstream_builder.h"
-#include "mongo/logger/tee.h"
-#include "mongo/logv2/log_component.h"
-#include "mongo/logv2/log_component_settings.h"
-#include "mongo/logv2/log_manager.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/errno_util.h"
#include "mongo/util/log_global_settings.h"
namespace mongo {
-namespace logger {
-typedef void (*ExtraLogContextFn)(BufBuilder& builder);
-Status registerExtraLogContextFn(ExtraLogContextFn contextFn);
-
-} // namespace logger
-
/*
* Although this is a "header" file, it is only supposed to be included in C++ files. The
* definitions of the following objects and functions (in the below anonymous namespace) will
@@ -85,7 +72,6 @@ const ::mongo::logger::LogComponent MongoLogDefaultComponent_component =
#endif // MONGO_LOG_DEFAULT_COMPONENT
using logger::LogstreamBuilderDeprecated;
-using logger::Tee;
/**
* Returns a LogstreamBuilder for logging a message with LogSeverity::Severe().
@@ -172,10 +158,8 @@ inline LogstreamBuilderDeprecated log(logger::LogComponent::Value componentValue
// this can't be in log_global_settings.h because it utilizes MongoLogDefaultComponent_component
inline bool shouldLogV1(logger::LogSeverity severity) {
- if (logV2Enabled())
- return logv2::LogManager::global().getGlobalSettings().shouldLog(
- logComponentV1toV2(MongoLogDefaultComponent_component), logSeverityV1toV2(severity));
- return mongo::shouldLogV1(MongoLogDefaultComponent_component, severity);
+ return logv2::LogManager::global().getGlobalSettings().shouldLog(
+ logComponentV1toV2(MongoLogDefaultComponent_component), logSeverityV1toV2(severity));
}
// MONGO_LOG uses log component from MongoLogDefaultComponent from current or global namespace.
@@ -201,9 +185,6 @@ inline bool shouldLogV1(logger::LogSeverity severity) {
::mongo::LogstreamBuilderDeprecated::severityCast(DLEVEL), \
(COMPONENT1))
-extern Tee* const warnings; // Things put here go in serverStatus
-extern Tee* const startupWarningsLog; // Things put here get reported in MMS
-
} // namespace mongo
#endif // MONGO_UTIL_LOG_H_
diff --git a/src/mongo/logv2/log_options.h b/src/mongo/logv2/log_options.h
index 1130992b08b..d0a4316e3da 100644
--- a/src/mongo/logv2/log_options.h
+++ b/src/mongo/logv2/log_options.h
@@ -70,6 +70,9 @@ public:
LogOptions(FatalMode mode) : _fatalMode(mode) {}
+ LogOptions(FatalMode mode, LogTruncation truncation)
+ : _truncation(truncation), _fatalMode(mode) {}
+
LogOptions(LogTag tags, LogTruncation truncation) : _tags(tags), _truncation(truncation) {}
LogOptions(LogComponent component, LogDomain* domain, LogTag tags)
diff --git a/src/mongo/logv2/logv2_bm.cpp b/src/mongo/logv2/logv2_bm.cpp
index db09d3026da..1154e0d2456 100644
--- a/src/mongo/logv2/logv2_bm.cpp
+++ b/src/mongo/logv2/logv2_bm.cpp
@@ -27,18 +27,13 @@
* it in the license file.
*/
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
-#include "mongo/logger/console_appender.h"
-#include "mongo/logger/logger.h"
-#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logv2/component_settings_filter.h"
#include "mongo/logv2/log.h"
#include "mongo/logv2/log_domain_global.h"
#include "mongo/logv2/text_formatter.h"
#include "mongo/platform/basic.h"
-#include "mongo/util/log.h"
#include <benchmark/benchmark.h>
#include <boost/iostreams/device/null.hpp>
@@ -57,64 +52,6 @@ boost::shared_ptr<std::ostream> makeNullStream() {
return boost::make_shared<bios::stream<bios::null_sink>>(bios::null_sink{});
}
-// Class with same interface as Console but uses a boost null_sink internally. So the
-// ConsoleAppender can be benchmarked.
-class StringstreamConsole {
-public:
- Mutex& mutex() {
- static auto instance = MONGO_MAKE_LATCH();
- return instance;
- }
-
- StringstreamConsole() {
- stdx::unique_lock<Latch> lk(mutex());
- lk.swap(_consoleLock);
- _out = makeNullStream();
- }
-
- std::ostream& out() {
- return *_out;
- }
-
-private:
- boost::shared_ptr<std::ostream> _out;
- stdx::unique_lock<Latch> _consoleLock;
-};
-
-// RAII style helper class for init/deinit log system
-class ScopedLogBench {
-public:
- ScopedLogBench(benchmark::State& state) {
- _shouldInit = state.thread_index == 0;
- if (_shouldInit) {
- setupAppender();
- }
- }
-
- ~ScopedLogBench() {
- if (_shouldInit) {
- tearDownAppender();
- }
- }
-
-private:
- void setupAppender() {
- logger::globalLogManager()->detachDefaultConsoleAppender();
- _appender = logger::globalLogDomain()->attachAppender(
- std::make_unique<
- logger::ConsoleAppender<logger::MessageEventEphemeral, StringstreamConsole>>(
- std::make_unique<logger::MessageEventDetailsEncoder>()));
- }
-
- void tearDownAppender() {
- logger::globalLogDomain()->detachAppender(_appender);
- logger::globalLogManager()->reattachDefaultConsoleAppender();
- }
-
- logger::ComponentMessageLogDomain::AppenderHandle _appender;
- bool _shouldInit;
-};
-
// RAII style helper class for init/deinit new log system
class ScopedLogV2Bench {
public:
@@ -166,13 +103,6 @@ std::string createLongString() {
std::string(1000, 'd') + std::string(1000, 'e');
}
-void BM_NoopLog(benchmark::State& state) {
- ScopedLogBench init(state);
-
- for (auto _ : state)
- MONGO_LOG(1) << "noop log";
-}
-
void BM_NoopLogV2(benchmark::State& state) {
ScopedLogV2Bench init(state);
@@ -180,13 +110,6 @@ void BM_NoopLogV2(benchmark::State& state) {
LOGV2_DEBUG(20074, 1, "noop log");
}
-void BM_NoopLogArg(benchmark::State& state) {
- ScopedLogBench init(state);
-
- for (auto _ : state)
- MONGO_LOG(1) << "noop log " << createLongString();
-}
-
void BM_NoopLogV2Arg(benchmark::State& state) {
ScopedLogV2Bench init(state);
@@ -194,14 +117,6 @@ void BM_NoopLogV2Arg(benchmark::State& state) {
LOGV2_DEBUG(20075, 1, "noop log {}", "str"_attr = createLongString());
}
-void BM_EnabledLog(benchmark::State& state) {
- ScopedLogBench init(state);
-
- for (auto _ : state)
- log() << "enabled log";
-}
-
-
void BM_EnabledLogV2(benchmark::State& state) {
ScopedLogV2Bench init(state);
@@ -209,14 +124,6 @@ void BM_EnabledLogV2(benchmark::State& state) {
LOGV2(20071, "enabled log");
}
-void BM_EnabledLogExpensiveArg(benchmark::State& state) {
- ScopedLogBench init(state);
-
- for (auto _ : state)
- log() << "enabled log " << createLongString();
-}
-
-
void BM_EnabledLogV2ExpensiveArg(benchmark::State& state) {
ScopedLogV2Bench init(state);
@@ -224,16 +131,6 @@ void BM_EnabledLogV2ExpensiveArg(benchmark::State& state) {
LOGV2(20072, "enabled log {}", "str"_attr = createLongString());
}
-void BM_EnabledLogManySmallArg(benchmark::State& state) {
- ScopedLogBench init(state);
-
- for (auto _ : state)
- log() << "enabled log " << 1 << 2 << "3" << 4.0 << "5"
- << "6"_sd << 7 << 8 << "9"
- << "10"_sd;
-}
-
-
void BM_EnabledLogV2ManySmallArg(benchmark::State& state) {
ScopedLogV2Bench init(state);
@@ -259,19 +156,10 @@ void ThreadCounts(benchmark::internal::Benchmark* b) {
b->Threads(t);
}
-BENCHMARK(BM_NoopLog)->Apply(ThreadCounts);
BENCHMARK(BM_NoopLogV2)->Apply(ThreadCounts);
-
-BENCHMARK(BM_NoopLogArg)->Apply(ThreadCounts);
BENCHMARK(BM_NoopLogV2Arg)->Apply(ThreadCounts);
-
-BENCHMARK(BM_EnabledLog)->Apply(ThreadCounts);
BENCHMARK(BM_EnabledLogV2)->Apply(ThreadCounts);
-
-BENCHMARK(BM_EnabledLogExpensiveArg)->Apply(ThreadCounts);
BENCHMARK(BM_EnabledLogV2ExpensiveArg)->Apply(ThreadCounts);
-
-BENCHMARK(BM_EnabledLogManySmallArg)->Apply(ThreadCounts);
BENCHMARK(BM_EnabledLogV2ManySmallArg)->Apply(ThreadCounts);
} // namespace
diff --git a/src/mongo/logv2/redaction_test.cpp b/src/mongo/logv2/redaction_test.cpp
index ca71e345ab5..f5df641e3e4 100644
--- a/src/mongo/logv2/redaction_test.cpp
+++ b/src/mongo/logv2/redaction_test.cpp
@@ -34,7 +34,6 @@
#include "mongo/db/jsobj.h"
#include "mongo/logv2/log_util.h"
#include "mongo/unittest/unittest.h"
-#include "mongo/util/log.h"
namespace mongo {
namespace {
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index 456faf068ad..4b711f91cc0 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -58,7 +58,6 @@
#include "mongo/db/server_options.h"
#include "mongo/logger/console_appender.h"
#include "mongo/logger/logger.h"
-#include "mongo/logger/logv2_appender.h"
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logv2/attributes.h"
#include "mongo/logv2/component_settings_filter.h"
@@ -75,6 +74,7 @@
#include "mongo/shell/shell_utils_launcher.h"
#include "mongo/stdx/utility.h"
#include "mongo/transport/transport_layer_asio.h"
+#include "mongo/util/errno_util.h"
#include "mongo/util/exit.h"
#include "mongo/util/file.h"
#include "mongo/util/log_global_settings.h"
@@ -729,19 +729,6 @@ int _main(int argc, char* argv[], char** envp) {
// Log to stdout for any early logging before we re-configure the logger
auto& lv2Manager = logv2::LogManager::global();
logv2::LogDomainGlobal::ConfigurationOptions lv2Config;
- if (logV2Enabled()) {
- logger::globalLogManager()->getGlobalDomain()->clearAppenders();
- logger::globalLogManager()->getGlobalDomain()->attachAppender(
- std::make_unique<logger::LogV2Appender<logger::MessageEventEphemeral>>(
- &lv2Manager.getGlobalDomain(), false));
- } else {
- logger::globalLogManager()->getGlobalDomain()->clearAppenders();
- logger::globalLogManager()->getGlobalDomain()->attachAppender(
- std::make_unique<ShellConsoleAppender>(
- std::make_unique<logger::MessageEventDetailsEncoder>()));
-
- lv2Config.makeDisabled();
- }
uassertStatusOK(lv2Manager.getGlobalDomainInternal().configure(lv2Config));
mongo::shell_utils::RecordMyLocation(argv[0]);
@@ -771,38 +758,22 @@ int _main(int argc, char* argv[], char** envp) {
if (!mongo::serverGlobalParams.quiet.load())
std::cout << mongoShellVersion(VersionInfoInterface::instance()) << std::endl;
- if (!logV2Enabled()) {
- logger::globalLogManager()
- ->getNamedDomain("plainShellOutput")
- ->attachAppender(std::make_unique<ShellConsoleAppender>(
- std::make_unique<logger::MessageEventUnadornedEncoder>()));
- } else {
- logger::globalLogManager()->getGlobalDomain()->clearAppenders();
- logger::globalLogManager()->getGlobalDomain()->attachAppender(
- std::make_unique<logger::LogV2Appender<logger::MessageEventEphemeral>>(
- &(lv2Manager.getGlobalDomain()), false));
- logger::globalLogManager()
- ->getNamedDomain("plainShellOutput")
- ->attachAppender(std::make_unique<logger::LogV2Appender<logger::MessageEventEphemeral>>(
- &lv2Manager.getGlobalDomain(), false, logv2::LogTag::kPlainShell));
-
- auto consoleSink = boost::make_shared<boost::log::sinks::synchronous_sink<ShellBackend>>();
- consoleSink->set_filter(logv2::ComponentSettingsFilter(lv2Manager.getGlobalDomain(),
- lv2Manager.getGlobalSettings()));
- consoleSink->set_formatter(ShellFormatter());
-
- consoleSink->locked_backend()->add_stream(
- boost::shared_ptr<std::ostream>(&logv2::Console::out(), boost::null_deleter()));
-
- consoleSink->locked_backend()->auto_flush();
-
- // Remove the initial config from above when setting this sink, otherwise we log everything
- // twice.
- lv2Config.makeDisabled();
- uassertStatusOK(lv2Manager.getGlobalDomainInternal().configure(lv2Config));
-
- boost::log::core::get()->add_sink(std::move(consoleSink));
- }
+ auto consoleSink = boost::make_shared<boost::log::sinks::synchronous_sink<ShellBackend>>();
+ consoleSink->set_filter(logv2::ComponentSettingsFilter(lv2Manager.getGlobalDomain(),
+ lv2Manager.getGlobalSettings()));
+ consoleSink->set_formatter(ShellFormatter());
+
+ consoleSink->locked_backend()->add_stream(
+ boost::shared_ptr<std::ostream>(&logv2::Console::out(), boost::null_deleter()));
+
+ consoleSink->locked_backend()->auto_flush();
+
+ // Remove the initial config from above when setting this sink, otherwise we log everything
+ // twice.
+ lv2Config.makeDisabled();
+ uassertStatusOK(lv2Manager.getGlobalDomainInternal().configure(lv2Config));
+
+ boost::log::core::get()->add_sink(std::move(consoleSink));
// Get the URL passed to the shell
std::string& cmdlineURI = shellGlobalParams.url;
diff --git a/src/mongo/util/log.cpp b/src/mongo/util/log.cpp
deleted file mode 100644
index 31b5824282a..00000000000
--- a/src/mongo/util/log.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * 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
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * 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 Server Side 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.
- */
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kControl
-#define MONGO_LOGV2_DEFAULT_COMPONENT mongo::logv2::LogComponent::kControl
-
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/logv2/log.h"
-#include "mongo/util/log.h"
-
-#include "mongo/config.h"
-#include "mongo/db/server_options.h"
-#include "mongo/logger/console_appender.h"
-#include "mongo/logger/message_event_utf8_encoder.h"
-#include "mongo/logger/ramlog.h"
-#include "mongo/logger/rotatable_file_manager.h"
-#include "mongo/logv2/log_domain.h"
-#include "mongo/logv2/log_domain_global.h"
-#include "mongo/logv2/log_manager.h"
-#include "mongo/util/assert_util.h"
-#include "mongo/util/concurrency/thread_name.h"
-#include "mongo/util/stacktrace.h"
-#include "mongo/util/time_support.h"
-
-// TODO: Win32 unicode console writing (in logger/console_appender?).
-// TODO: Extra log context appending, and re-enable log_user_*.js
-// TODO: Eliminate cout/cerr.
-
-namespace mongo {
-
-bool logV2Enabled() {
- return true;
-}
-
-bool logV2IsJson(logv2::LogFormat format) {
- return format == logv2::LogFormat::kJson || format == logv2::LogFormat::kDefault;
-}
-
-static logger::ExtraLogContextFn _appendExtraLogContext;
-
-Status logger::registerExtraLogContextFn(logger::ExtraLogContextFn contextFn) {
- if (!contextFn)
- return Status(ErrorCodes::BadValue, "Cannot register a NULL log context function.");
- if (_appendExtraLogContext) {
- return Status(ErrorCodes::AlreadyInitialized,
- "Cannot call registerExtraLogContextFn multiple times.");
- }
- _appendExtraLogContext = contextFn;
- return Status::OK();
-}
-
-Tee* const startupWarningsLog = RamLog::get("startupWarnings"); // intentionally leaked
-
-} // namespace mongo
diff --git a/src/mongo/util/log_global_settings.h b/src/mongo/util/log_global_settings.h
index 9c8d149f7d7..807321a95e9 100644
--- a/src/mongo/util/log_global_settings.h
+++ b/src/mongo/util/log_global_settings.h
@@ -41,18 +41,13 @@
namespace mongo {
-bool logV2Enabled();
-bool logV2IsJson(logv2::LogFormat format);
-
/**
* Runs the same logic as log()/warning()/error(), without actually outputting a stream.
*/
-
inline bool shouldLogV1(logger::LogComponent logComponent1, logger::LogSeverity severity) {
- if (logV2Enabled())
- return logv2::LogManager::global().getGlobalSettings().shouldLog(
- logComponentV1toV2(logComponent1), logSeverityV1toV2(severity));
- return logger::globalLogDomain()->shouldLog(logComponent1, severity);
+
+ return logv2::LogManager::global().getGlobalSettings().shouldLog(
+ logComponentV1toV2(logComponent1), logSeverityV1toV2(severity));
}
} // namespace mongo
diff --git a/src/mongo/util/signal_handlers_synchronous.cpp b/src/mongo/util/signal_handlers_synchronous.cpp
index de02dd08d49..6eb4eb77449 100644
--- a/src/mongo/util/signal_handlers_synchronous.cpp
+++ b/src/mongo/util/signal_handlers_synchronous.cpp
@@ -44,8 +44,6 @@
#include <typeinfo>
#include "mongo/base/string_data.h"
-#include "mongo/logger/log_domain.h"
-#include "mongo/logger/logger.h"
#include "mongo/logv2/log.h"
#include "mongo/platform/compiler.h"
#include "mongo/stdx/exception.h"
@@ -193,13 +191,11 @@ thread_local int MallocFreeOStreamGuard::terminateDepth = 0;
// must hold MallocFreeOStreamGuard to call
void writeMallocFreeStreamToLog() {
- logger::globalLogDomain()
- ->append(logger::MessageEventEphemeral(Date_t::now(),
- logger::LogSeverity::Severe(),
- getThreadName(),
- mallocFreeOStream.str())
- .setIsTruncatable(false))
- .transitional_ignore();
+ LOGV2_FATAL_OPTIONS(
+ 4757800,
+ logv2::LogOptions(logv2::FatalMode::kContinue, logv2::LogTruncation::Disabled),
+ "{message}",
+ "message"_attr = mallocFreeOStream.str());
mallocFreeOStream.rewind();
}