summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2019-11-25 22:16:49 +0000
committerevergreen <evergreen@mongodb.com>2019-11-25 22:16:49 +0000
commita29cb7d084afa62772776fc2b58efb1df91c535f (patch)
tree4d75bc806f223b843f5f751936b53079d3c09896 /src
parentbd31dd168c29d5aaa5ae2822f5673eff7a2850d7 (diff)
downloadmongo-a29cb7d084afa62772776fc2b58efb1df91c535f.tar.gz
SERVER-44142 correctly utilize LogSeverity in logv2
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/generic_servers.cpp6
-rw-r--r--src/mongo/db/commands/parameters.cpp14
-rw-r--r--src/mongo/db/initialize_server_global_state.cpp10
-rw-r--r--src/mongo/db/repl/apply_ops_test.cpp7
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp4
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp8
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp4
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp8
-rw-r--r--src/mongo/db/repl/rollback_test_fixture.cpp5
-rw-r--r--src/mongo/db/repl/topology_coordinator.cpp4
-rw-r--r--src/mongo/db/repl/topology_coordinator_v1_test.cpp5
-rw-r--r--src/mongo/db/s/transaction_coordinator_test.cpp15
-rw-r--r--src/mongo/db/server_options.h3
-rw-r--r--src/mongo/db/server_options_helpers.cpp18
-rw-r--r--src/mongo/db/server_options_test.cpp100
-rw-r--r--src/mongo/db/service_entry_point_common.cpp3
-rw-r--r--src/mongo/db/storage/mobile/mobile_sqlite_statement.cpp7
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp9
-rw-r--r--src/mongo/db/transaction_participant_test.cpp10
-rw-r--r--src/mongo/dbtests/framework_options.cpp2
-rw-r--r--src/mongo/logger/log_component_settings_test.cpp12
-rw-r--r--src/mongo/logger/log_function_test.cpp8
-rw-r--r--src/mongo/logger/log_test.cpp48
-rw-r--r--src/mongo/logger/log_test.h5
-rw-r--r--src/mongo/logger/logv2_appender.h24
-rw-r--r--src/mongo/rpc/op_msg_test.cpp9
-rw-r--r--src/mongo/s/client/shard_remote.cpp5
-rw-r--r--src/mongo/s/mongos_options.cpp3
-rw-r--r--src/mongo/s/transaction_router_test.cpp6
-rw-r--r--src/mongo/shell/dbshell.cpp2
-rw-r--r--src/mongo/shell/shell_options.cpp4
-rw-r--r--src/mongo/shell/shell_options.h2
-rw-r--r--src/mongo/tools/mongobridge_options.cpp3
-rw-r--r--src/mongo/unittest/unittest_main.cpp4
-rw-r--r--src/mongo/util/log.cpp15
-rw-r--r--src/mongo/util/log.h59
-rw-r--r--src/mongo/util/log_global_settings.h101
-rw-r--r--src/mongo/util/signal_handlers.cpp3
38 files changed, 294 insertions, 261 deletions
diff --git a/src/mongo/db/commands/generic_servers.cpp b/src/mongo/db/commands/generic_servers.cpp
index 073a67b22d2..88c137982a9 100644
--- a/src/mongo/db/commands/generic_servers.cpp
+++ b/src/mongo/db/commands/generic_servers.cpp
@@ -196,7 +196,7 @@ public:
const std::string& ns,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
- bool didRotate = rotateLogs(serverGlobalParams.logRenameOnRotate, serverGlobalParams.logV2);
+ bool didRotate = rotateLogs(serverGlobalParams.logRenameOnRotate, logV2Enabled());
if (didRotate)
logProcessDetailsForLogRotate(opCtx->getServiceContext());
return didRotate;
@@ -233,7 +233,7 @@ public:
const BSONObj& cmdObj,
std::string& errmsg,
BSONObjBuilder& result) override {
- if (serverGlobalParams.logV2) {
+ if (logV2Enabled()) {
return errmsgRunImpl<logv2::RamLog>(opCtx, dbname, cmdObj, errmsg, result);
}
return errmsgRunImpl<RamLog>(opCtx, dbname, cmdObj, errmsg, result);
@@ -322,7 +322,7 @@ public:
invariant(ramlog);
ramlog->clear();
};
- if (serverGlobalParams.logV2) {
+ if (logV2Enabled()) {
clearRamlog(logv2::RamLog::getIfExists(logName));
} else {
clearRamlog(RamLog::getIfExists(logName));
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index 625b3aaee76..a189e6f3426 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -101,8 +101,8 @@ void getLogComponentVerbosity(BSONObj* output) {
LogComponent component = static_cast<LogComponent::Value>(i);
int severity = -1;
- if (globalLogDomain()->hasMinimumLogSeverity(component)) {
- severity = globalLogDomain()->getMinimumLogSeverity(component).toInt();
+ if (hasMinimumLogSeverity(component)) {
+ severity = getMinimumLogSeverity(component).toInt();
}
// Save LogComponent::kDefault LogSeverity at root
@@ -172,13 +172,13 @@ Status setLogComponentVerbosity(const BSONObj& bsonSettings) {
// Negative value means to clear log level of component.
if (newSetting.level < 0) {
- globalLogDomain()->clearMinimumLoggedSeverity(newSetting.component);
+ clearMinimumLoggedSeverity(newSetting.component);
continue;
}
// Convert non-negative value to Log()/Debug(N).
LogSeverity newSeverity =
(newSetting.level > 0) ? LogSeverity::Debug(newSetting.level) : LogSeverity::Log();
- globalLogDomain()->setMinimumLoggedSeverity(newSetting.component, newSeverity);
+ setMinimumLoggedSeverity(newSetting.component, newSeverity);
}
return Status::OK();
@@ -384,7 +384,7 @@ public:
void LogLevelServerParameter::append(OperationContext*,
BSONObjBuilder& builder,
const std::string& name) {
- builder.append(name, globalLogDomain()->getMinimumLogSeverity().toInt());
+ builder.append(name, getMinimumLogSeverity().toInt());
}
Status LogLevelServerParameter::set(const BSONElement& newValueElement) {
@@ -393,7 +393,7 @@ Status LogLevelServerParameter::set(const BSONElement& newValueElement) {
return Status(ErrorCodes::BadValue,
str::stream() << "Invalid value for logLevel: " << newValueElement);
LogSeverity newSeverity = (newValue > 0) ? LogSeverity::Debug(newValue) : LogSeverity::Log();
- globalLogDomain()->setMinimumLoggedSeverity(newSeverity);
+ setMinimumLoggedSeverity(newSeverity);
return Status::OK();
}
@@ -406,7 +406,7 @@ Status LogLevelServerParameter::setFromString(const std::string& strLevel) {
return Status(ErrorCodes::BadValue,
str::stream() << "Invalid value for logLevel: " << newValue);
LogSeverity newSeverity = (newValue > 0) ? LogSeverity::Debug(newValue) : LogSeverity::Log();
- globalLogDomain()->setMinimumLoggedSeverity(newSeverity);
+ setMinimumLoggedSeverity(newSeverity);
return Status::OK();
}
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp
index 174a7d1cddd..9a4fdc57a1f 100644
--- a/src/mongo/db/initialize_server_global_state.cpp
+++ b/src/mongo/db/initialize_server_global_state.cpp
@@ -233,7 +233,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
std::unique_ptr<logger::Appender<MessageEventEphemeral>> appender;
std::unique_ptr<logger::Appender<MessageEventEphemeral>> javascriptAppender;
- if (serverGlobalParams.logV2) {
+ if (logV2Enabled()) {
appender = std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
&(lv2Manager.getGlobalDomain()));
javascriptAppender = std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
@@ -302,7 +302,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
std::unique_ptr<logger::Appender<MessageEventEphemeral>> appender;
std::unique_ptr<logger::Appender<MessageEventEphemeral>> javascriptAppender;
- if (serverGlobalParams.logV2) {
+ if (logV2Enabled()) {
appender = std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
&(lv2Manager.getGlobalDomain()));
@@ -350,7 +350,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
manager->getNamedDomain("javascriptOutput")->attachAppender(std::move(javascriptAppender));
} else {
- if (serverGlobalParams.logV2) {
+ if (logV2Enabled()) {
manager->getGlobalDomain()->clearAppenders();
manager->getGlobalDomain()->attachAppender(
std::make_unique<logger::LogV2Appender<MessageEventEphemeral>>(
@@ -365,13 +365,13 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
std::make_unique<MessageEventDetailsEncoder>()));
}
}
- if (!serverGlobalParams.logV2) {
+ if (!logV2Enabled()) {
logger::globalLogDomain()->attachAppender(
std::make_unique<RamLogAppender>(RamLog::get("global")));
}
- if (serverGlobalParams.logV2) {
+ if (logV2Enabled()) {
lv2Config._format = serverGlobalParams.logFormat;
return lv2Manager.getGlobalDomainInternal().configure(lv2Config);
}
diff --git a/src/mongo/db/repl/apply_ops_test.cpp b/src/mongo/db/repl/apply_ops_test.cpp
index b5ddfadcd0f..9fe27a8c8a1 100644
--- a/src/mongo/db/repl/apply_ops_test.cpp
+++ b/src/mongo/db/repl/apply_ops_test.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/logger/logger.h"
#include "mongo/rpc/get_status_from_command_result.h"
+#include "mongo/util/log_global_settings.h"
namespace mongo {
namespace repl {
@@ -115,8 +116,7 @@ void ApplyOpsTest::tearDown() {
_opObserver = nullptr;
// Reset default log level in case it was changed.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kReplication,
- logger::LogSeverity::Debug(0));
+ setMinimumLoggedSeverity(logger::LogComponent::kReplication, logger::LogSeverity::Debug(0));
ServiceContextMongoDTest::tearDown();
}
@@ -290,8 +290,7 @@ TEST_F(ApplyOpsTest, ApplyOpsPropagatesOplogApplicationMode) {
auto opCtx = cc().makeOperationContext();
// Increase log component verbosity to check for op application messages.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kReplication,
- logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logger::LogComponent::kReplication, logger::LogSeverity::Debug(3));
// Test that the 'applyOps' function passes the oplog application mode through correctly to the
// underlying op application functions.
diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
index 2ab89c5a33a..0fca53d51c1 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
@@ -515,7 +515,7 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) {
ASSERT_EQUALS(ErrorCodes::ConfigurationInProgress,
getReplCoord()->processReplSetReconfig(&opCtx, args, &result));
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(2));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(2));
startCapturingLogMessages();
// receive sufficient heartbeats to allow the node to see a majority.
@@ -1101,7 +1101,7 @@ TEST_F(TakeoverTest, PrefersPriorityToCatchupTakeoverIfNodeHasHighestPriority) {
<< "node3:12345"))
<< "protocolVersion" << 1);
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(2));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(2));
startCapturingLogMessages();
assertStartSuccess(configObj, HostAndPort("node1", 12345));
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
index 18e33db8083..8edd471fd7a 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
@@ -85,7 +85,7 @@ ReplSetHeartbeatResponse ReplCoordHBV1Test::receiveHeartbeatFrom(const ReplSetCo
TEST_F(ReplCoordHBV1Test,
NodeJoinsExistingReplSetWhenReceivingAConfigContainingTheNodeViaHeartbeat) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id"
<< "mySet"
<< "version" << 3 << "members"
@@ -154,7 +154,7 @@ TEST_F(ReplCoordHBV1Test,
TEST_F(ReplCoordHBV1Test,
ArbiterJoinsExistingReplSetWhenReceivingAConfigContainingTheArbiterViaHeartbeat) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
ReplSetConfig rsConfig =
assertMakeRSConfig(BSON("_id"
<< "mySet"
@@ -227,7 +227,7 @@ TEST_F(ReplCoordHBV1Test,
NodeDoesNotJoinExistingReplSetWhenReceivingAConfigNotContainingTheNodeViaHeartbeat) {
// Tests that a node in RS_STARTUP will not transition to RS_REMOVED if it receives a
// configuration that does not contain it.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id"
<< "mySet"
<< "version" << 3 << "members"
@@ -309,7 +309,7 @@ TEST_F(ReplCoordHBV1Test,
TEST_F(ReplCoordHBV1Test,
NodeChangesToRecoveringStateWhenAllNodesRespondToHeartbeatsWithUnauthorized) {
// Tests that a node that only has auth error heartbeats is recovering
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
diff --git a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
index 276148da179..92ea7ea3aa8 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
@@ -564,7 +564,7 @@ TEST_F(ReplCoordTest, NodeDoesNotAcceptHeartbeatReconfigWhileInTheMidstOfReconfi
hbResp.addToBSON(&respObj2);
net->scheduleResponse(noi, net->now(), makeResponseStatus(respObj2.obj()));
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
startCapturingLogMessages();
// execute hb reconfig, which should fail with a log message; confirmed at end of test
net->runReadyNetworkOperations();
@@ -575,7 +575,7 @@ TEST_F(ReplCoordTest, NodeDoesNotAcceptHeartbeatReconfigWhileInTheMidstOfReconfi
1, countLogLinesContaining("because already in the midst of a configuration process"));
shutdown(opCtx.get());
reconfigThread.join();
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logger::LogSeverity::Log());
}
TEST_F(ReplCoordTest, NodeAcceptsConfigFromAReconfigWithForceTrueWhileNotPrimary) {
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index 0091850e6ef..658487d6333 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -5161,8 +5161,8 @@ TEST_F(ReplCoordTest,
TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) {
// Log all the election messages.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kReplicationElection,
- logger::LogSeverity::Debug(5));
+ setMinimumLoggedSeverity(logger::LogComponent::kReplicationElection,
+ logger::LogSeverity::Debug(5));
startCapturingLogMessages();
// heartbeatTimeoutSecs is made large so we can advance the clock without worrying about
// additional heartbeats.
@@ -5217,8 +5217,8 @@ TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) {
ASSERT_EQ(1, countLogLinesContaining("Rescheduling election timeout callback"));
ASSERT_EQ(1, countLogLinesContaining("Canceling election timeout callback"));
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kReplicationElection,
- logger::LogSeverity::Debug(4));
+ setMinimumLoggedSeverity(logger::LogComponent::kReplicationElection,
+ logger::LogSeverity::Debug(4));
net->enterNetwork();
until = electionTimeoutWhen + Milliseconds(500);
net->runUntil(until);
diff --git a/src/mongo/db/repl/rollback_test_fixture.cpp b/src/mongo/db/repl/rollback_test_fixture.cpp
index d0b0463fe07..805332fb56a 100644
--- a/src/mongo/db/repl/rollback_test_fixture.cpp
+++ b/src/mongo/db/repl/rollback_test_fixture.cpp
@@ -49,6 +49,7 @@
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/logger/log_component.h"
#include "mongo/logger/logger.h"
+#include "mongo/util/log_global_settings.h"
#include "mongo/util/str.h"
namespace mongo {
@@ -109,8 +110,8 @@ void RollbackTest::setUp() {
_replicationProcess->initializeRollbackID(_opCtx.get()).transitional_ignore();
// Increase rollback log component verbosity for unit tests.
- mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- logger::LogComponent::kReplicationRollback, logger::LogSeverity::Debug(2));
+ setMinimumLoggedSeverity(logger::LogComponent::kReplicationRollback,
+ logger::LogSeverity::Debug(2));
auto observerRegistry = checked_cast<OpObserverRegistry*>(serviceContext->getOpObserver());
observerRegistry->addObserver(std::make_unique<RollbackTestOpObserver>());
diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp
index b95d813a3f0..0f88b5eec7c 100644
--- a/src/mongo/db/repl/topology_coordinator.cpp
+++ b/src/mongo/db/repl/topology_coordinator.cpp
@@ -756,8 +756,8 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse(
} else {
LOG(2) << "Config from heartbeat response was same as ours.";
}
- if (logger::globalLogDomain()->shouldLog(MongoLogDefaultComponent_component,
- ::mongo::LogstreamBuilder::severityCast(2))) {
+ if (shouldLog(MongoLogDefaultComponent_component,
+ ::mongo::LogstreamBuilder::severityCast(2))) {
LogstreamBuilder lsb = log();
if (_rsConfig.isInitialized()) {
lsb << "Current config: " << _rsConfig.toBSON() << "; ";
diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
index 797898136c5..2ea7224b005 100644
--- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
@@ -46,6 +46,7 @@
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/log_global_settings.h"
#include "mongo/util/net/hostandport.h"
#include "mongo/util/net/socket_utils.h"
#include "mongo/util/scopeguard.h"
@@ -5778,12 +5779,12 @@ public:
virtual void setUp() {
HeartbeatResponseTestV1::setUp();
// set verbosity as high as the highest verbosity log message we'd like to check for
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
}
virtual void tearDown() {
HeartbeatResponseTestV1::tearDown();
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logger::LogSeverity::Log());
}
};
diff --git a/src/mongo/db/s/transaction_coordinator_test.cpp b/src/mongo/db/s/transaction_coordinator_test.cpp
index a97eb12a720..d21e4caf34b 100644
--- a/src/mongo/db/s/transaction_coordinator_test.cpp
+++ b/src/mongo/db/s/transaction_coordinator_test.cpp
@@ -2109,15 +2109,13 @@ TEST_F(TransactionCoordinatorMetricsTest, CoordinatorsAWSIsShutDownWhileCoordina
}
TEST_F(TransactionCoordinatorMetricsTest, LogsTransactionAtLogLevelOne) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Debug(1));
runSimpleTwoPhaseCommitWithCommitDecisionAndCaptureLogLines();
ASSERT_EQUALS(1, countLogLinesContaining("two-phase commit parameters:"));
}
TEST_F(TransactionCoordinatorMetricsTest, DoesNotLogTransactionAtLogLevelZero) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
runSimpleTwoPhaseCommitWithCommitDecisionAndCaptureLogLines();
ASSERT_EQUALS(0, countLogLinesContaining("two-phase commit parameters:"));
}
@@ -2125,8 +2123,7 @@ TEST_F(TransactionCoordinatorMetricsTest, DoesNotLogTransactionAtLogLevelZero) {
TEST_F(TransactionCoordinatorMetricsTest, DoesNotLogTransactionsUnderSlowMSThreshold) {
// Set the log level to 0 so that the slow logging is only done if the transaction exceeds the
// slowMS setting.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
serverGlobalParams.slowMS = 100;
startCapturingLogMessages();
@@ -2157,8 +2154,7 @@ TEST_F(
DoesNotLogTransactionsUnderSlowMSThresholdEvenIfCoordinatorHasExistedForLongerThanSlowThreshold) {
// Set the log level to 0 so that the slow logging is only done if the transaction exceeds the
// slowMS setting.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
serverGlobalParams.slowMS = 100;
startCapturingLogMessages();
@@ -2187,8 +2183,7 @@ TEST_F(
TEST_F(TransactionCoordinatorMetricsTest, LogsTransactionsOverSlowMSThreshold) {
// Set the log level to 0 so that the slow logging is only done if the transaction exceeds the
// slowMS setting.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
serverGlobalParams.slowMS = 100;
startCapturingLogMessages();
diff --git a/src/mongo/db/server_options.h b/src/mongo/db/server_options.h
index f6d060837a3..2a7796f9307 100644
--- a/src/mongo/db/server_options.h
+++ b/src/mongo/db/server_options.h
@@ -102,8 +102,7 @@ struct ServerGlobalParams {
bool logAppend = false; // True if logging to a file in append mode.
bool logRenameOnRotate = true; // True if logging should rename log files on rotate
bool logWithSyslog = false; // True if logging to syslog; must not be set if logpath is set.
- bool logV2 = false; // True if logV1 logging statements should get plumbed through to logV2
- int syslogFacility; // Facility used when appending messages to the syslog.
+ int syslogFacility; // Facility used when appending messages to the syslog.
#ifndef _WIN32
ProcessId parentProc; // --fork pid of initial process
diff --git a/src/mongo/db/server_options_helpers.cpp b/src/mongo/db/server_options_helpers.cpp
index 17914692b35..5fc7039d866 100644
--- a/src/mongo/db/server_options_helpers.cpp
+++ b/src/mongo/db/server_options_helpers.cpp
@@ -53,6 +53,7 @@
#include "mongo/util/cmdline_utils/censor_cmdline.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
+#include "mongo/util/log_global_settings.h"
#include "mongo/util/map_util.h"
#include "mongo/util/net/sock.h"
#include "mongo/util/net/socket_utils.h"
@@ -263,6 +264,10 @@ Status storeBaseOptions(const moe::Environment& params) {
return ret;
}
+ if (params.count("logv2")) {
+ logV2Set(true);
+ }
+
if (params.count("systemLog.verbosity")) {
int verbosity = params["systemLog.verbosity"].as<int>();
if (verbosity < 0) {
@@ -270,7 +275,7 @@ Status storeBaseOptions(const moe::Environment& params) {
return Status(ErrorCodes::BadValue,
"systemLog.verbosity YAML Config cannot be negative");
}
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(verbosity));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(verbosity));
}
// log component hierarchy verbosity levels
@@ -284,10 +289,9 @@ Status storeBaseOptions(const moe::Environment& params) {
int verbosity = params[dottedName].as<int>();
// Clear existing log level if log level is negative.
if (verbosity < 0) {
- logger::globalLogDomain()->clearMinimumLoggedSeverity(component);
+ clearMinimumLoggedSeverity(component);
} else {
- logger::globalLogDomain()->setMinimumLoggedSeverity(
- component, logger::LogSeverity::Debug(verbosity));
+ setMinimumLoggedSeverity(component, logger::LogSeverity::Debug(verbosity));
}
}
}
@@ -321,9 +325,7 @@ Status storeBaseOptions(const moe::Environment& params) {
return Status(ErrorCodes::BadValue, sb.str());
}
}
- if (params.count("logv2")) {
- serverGlobalParams.logV2 = true;
- }
+
if (params.count("systemLog.destination")) {
std::string systemLogDestination = params["systemLog.destination"].as<std::string>();
if (systemLogDestination == "file") {
@@ -380,7 +382,7 @@ Status storeBaseOptions(const moe::Environment& params) {
if (params.count("systemLog.logFormat")) {
std::string formatStr = params["systemLog.logFormat"].as<string>();
- if (!serverGlobalParams.logV2 && formatStr != "default")
+ if (!logV2Enabled() && formatStr != "default")
return Status(ErrorCodes::BadValue,
"Can only use systemLog.logFormat if logv2 is enabled.");
if (formatStr == "default") {
diff --git a/src/mongo/db/server_options_test.cpp b/src/mongo/db/server_options_test.cpp
index 0b4ace14291..5eb7600696b 100644
--- a/src/mongo/db/server_options_test.cpp
+++ b/src/mongo/db/server_options_test.cpp
@@ -102,8 +102,7 @@ TEST(Verbosity, Default) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -119,8 +118,7 @@ TEST(Verbosity, Default) {
ASSERT_OK(::mongo::storeServerOptions(environment));
// Make sure the log level didn't change since we didn't specify any verbose options
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Info());
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Info());
}
TEST(Verbosity, CommandLineImplicit) {
@@ -129,8 +127,7 @@ TEST(Verbosity, CommandLineImplicit) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -147,8 +144,7 @@ TEST(Verbosity, CommandLineImplicit) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 1;
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, CommandLineString) {
@@ -157,8 +153,7 @@ TEST(Verbosity, CommandLineString) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -176,8 +171,7 @@ TEST(Verbosity, CommandLineString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, CommandLineStringDisguisedLongForm) {
@@ -186,8 +180,7 @@ TEST(Verbosity, CommandLineStringDisguisedLongForm) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -205,8 +198,7 @@ TEST(Verbosity, CommandLineStringDisguisedLongForm) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, CommandLineEmptyString) {
@@ -215,8 +207,7 @@ TEST(Verbosity, CommandLineEmptyString) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -235,8 +226,7 @@ TEST(Verbosity, CommandLineBadString) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -257,8 +247,7 @@ TEST(Verbosity, CommandLineBadStringOnlyDash) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -276,8 +265,7 @@ TEST(Verbosity, CommandLineBadStringOnlyTwoDashes) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -295,8 +283,7 @@ TEST(Verbosity, INIConfigString) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -316,8 +303,7 @@ TEST(Verbosity, INIConfigString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, INIConfigBadString) {
@@ -326,8 +312,7 @@ TEST(Verbosity, INIConfigBadString) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -350,8 +335,7 @@ TEST(Verbosity, INIConfigEmptyString) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -371,8 +355,7 @@ TEST(Verbosity, INIConfigEmptyString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 0;
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, JSONConfigString) {
@@ -381,8 +364,7 @@ TEST(Verbosity, JSONConfigString) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -402,8 +384,7 @@ TEST(Verbosity, JSONConfigString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, MultipleSourcesMultipleOptions) {
@@ -412,8 +393,7 @@ TEST(Verbosity, MultipleSourcesMultipleOptions) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -435,8 +415,7 @@ TEST(Verbosity, MultipleSourcesMultipleOptions) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 3;
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, YAMLConfigStringLogComponent) {
@@ -445,11 +424,10 @@ TEST(Verbosity, YAMLConfigStringLogComponent) {
moe::OptionSection options;
// Reset the log level before we test
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
// Log level for Storage will be cleared by config file value.
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogComponent::kStorage, ::mongo::logger::LogSeverity::Debug(1));
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogComponent::kStorage,
+ ::mongo::logger::LogSeverity::Debug(1));
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -481,38 +459,28 @@ TEST(Verbosity, YAMLConfigStringLogComponent) {
int verbosity = 4;
// Default
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(),
- ::mongo::logger::LogSeverity::Debug(verbosity));
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(
- ::mongo::logger::LogComponent::kDefault),
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kDefault),
::mongo::logger::LogSeverity::Debug(verbosity));
// AccessControl
- ASSERT_TRUE(::mongo::logger::globalLogDomain()->hasMinimumLogSeverity(
- ::mongo::logger::LogComponent::kAccessControl));
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(
- ::mongo::logger::LogComponent::kAccessControl),
+ ASSERT_TRUE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kAccessControl));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kAccessControl),
::mongo::logger::LogSeverity::Log());
// Query - not mentioned in configuration. should match default.
- ASSERT_FALSE(::mongo::logger::globalLogDomain()->hasMinimumLogSeverity(
- ::mongo::logger::LogComponent::kStorage));
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(
- ::mongo::logger::LogComponent::kStorage),
+ ASSERT_FALSE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kStorage));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kStorage),
::mongo::logger::LogSeverity::Debug(verbosity));
// Storage - cleared by -1 value in configuration. should match default.
- ASSERT_FALSE(::mongo::logger::globalLogDomain()->hasMinimumLogSeverity(
- ::mongo::logger::LogComponent::kStorage));
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(
- ::mongo::logger::LogComponent::kStorage),
+ ASSERT_FALSE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kStorage));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kStorage),
::mongo::logger::LogSeverity::Debug(verbosity));
// Journaling - explicitly set to 2 in configuration.
- ASSERT_TRUE(::mongo::logger::globalLogDomain()->hasMinimumLogSeverity(
- ::mongo::logger::LogComponent::kJournal));
- ASSERT_EQUALS(::mongo::logger::globalLogDomain()->getMinimumLogSeverity(
- ::mongo::logger::LogComponent::kJournal),
+ ASSERT_TRUE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kJournal));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kJournal),
::mongo::logger::LogSeverity::Debug(2));
}
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index 4a42657c92a..4c7f25518c3 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -978,8 +978,7 @@ void execCommandDatabase(OperationContext* opCtx,
command->incrementCommandsExecuted();
- if (logger::globalLogDomain()->shouldLog(logger::LogComponent::kTracking,
- logger::LogSeverity::Debug(1)) &&
+ if (shouldLog(logger::LogComponent::kTracking, logger::LogSeverity::Debug(1)) &&
rpc::TrackingMetadata::get(opCtx).getParentOperId()) {
MONGO_LOG_COMPONENT(1, logger::LogComponent::kTracking)
<< rpc::TrackingMetadata::get(opCtx).toString();
diff --git a/src/mongo/db/storage/mobile/mobile_sqlite_statement.cpp b/src/mongo/db/storage/mobile/mobile_sqlite_statement.cpp
index 7760dff5788..947746277cb 100644
--- a/src/mongo/db/storage/mobile/mobile_sqlite_statement.cpp
+++ b/src/mongo/db/storage/mobile/mobile_sqlite_statement.cpp
@@ -42,10 +42,9 @@
#include "mongo/util/scopeguard.h"
#define SQLITE_STMT_TRACE() LOG(MOBILE_TRACE_LEVEL) << "MobileSE: SQLite Stmt ID:" << _id << " "
-#define SQLITE_STMT_TRACE_ENABLED() \
- (::mongo::logger::globalLogDomain()->shouldLog( \
- MongoLogDefaultComponent_component, \
- ::mongo::LogstreamBuilder::severityCast(MOBILE_TRACE_LEVEL)))
+#define SQLITE_STMT_TRACE_ENABLED() \
+ (shouldLog(MongoLogDefaultComponent_component, \
+ ::mongo::LogstreamBuilder::severityCast(MOBILE_TRACE_LEVEL)))
namespace mongo {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
index 334cda5b748..76ab1239046 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
@@ -48,6 +48,7 @@
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
+#include "mongo/util/log_global_settings.h"
namespace mongo {
namespace {
@@ -253,11 +254,9 @@ TEST_F(WiredTigerKVEngineTest, TestOplogTruncation) {
// To diagnose any intermittent failures, maximize logging from WiredTigerKVEngine and friends.
const auto kStorage = logger::LogComponent::kStorage;
- auto originalVerbosity = logger::globalLogDomain()->getMinimumLogSeverity(kStorage);
- logger::globalLogDomain()->setMinimumLoggedSeverity(kStorage, logger::LogSeverity::Debug(3));
- ON_BLOCK_EXIT([&]() {
- logger::globalLogDomain()->setMinimumLoggedSeverity(kStorage, originalVerbosity);
- });
+ auto originalVerbosity = getMinimumLogSeverity(kStorage);
+ setMinimumLoggedSeverity(kStorage, logger::LogSeverity::Debug(3));
+ ON_BLOCK_EXIT([&]() { setMinimumLoggedSeverity(kStorage, originalVerbosity); });
// Simulate the callback that queries config.transactions for the oldest active transaction.
boost::optional<Timestamp> oldestActiveTxnTimestamp;
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index 32ddd12ea71..46a0b8f700e 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -58,6 +58,7 @@
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/fail_point.h"
+#include "mongo/util/log_global_settings.h"
#include "mongo/util/net/socket_utils.h"
#include "mongo/util/tick_source_mock.h"
@@ -3515,8 +3516,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoVerbosityInfo) {
serverGlobalParams.slowMS = 10000;
// Set verbosity level of transaction components to info.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Info());
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Info());
txnParticipant.unstashTransactionResources(opCtx(), "commitTransaction");
@@ -3537,8 +3537,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoVerbosityDebug) {
serverGlobalParams.slowMS = 10000;
// Set verbosity level of transaction components to debug.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Debug(1));
txnParticipant.unstashTransactionResources(opCtx(), "commitTransaction");
@@ -3547,8 +3546,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoVerbosityDebug) {
stopCapturingLogMessages();
// Reset verbosity level of transaction components.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Info());
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Info());
// Test that the transaction is still logged.
ASSERT_EQUALS(1, countLogLinesContaining("transaction parameters"));
diff --git a/src/mongo/dbtests/framework_options.cpp b/src/mongo/dbtests/framework_options.cpp
index ce60afc136a..d9743cb17b4 100644
--- a/src/mongo/dbtests/framework_options.cpp
+++ b/src/mongo/dbtests/framework_options.cpp
@@ -90,7 +90,7 @@ Status storeTestFrameworkOptions(const moe::Environment& params,
}
if (params.count("debug") || params.count("verbose")) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
}
boost::filesystem::path p(frameworkGlobalParams.dbpathSpec);
diff --git a/src/mongo/logger/log_component_settings_test.cpp b/src/mongo/logger/log_component_settings_test.cpp
index edb96307039..d5a2541d81b 100644
--- a/src/mongo/logger/log_component_settings_test.cpp
+++ b/src/mongo/logger/log_component_settings_test.cpp
@@ -35,6 +35,7 @@
#include "mongo/platform/atomic_word.h"
#include "mongo/stdx/thread.h"
#include "mongo/unittest/barrier.h"
+#include "mongo/util/log_global_settings.h"
#include "mongo/unittest/unittest.h"
@@ -52,31 +53,28 @@ TEST(SERVER25981Test, SetSeverityShouldLogAndClear) {
stdx::thread shouldLogThread([&]() {
startupBarrier.countDownAndWait();
while (running.load()) {
- logger::globalLogDomain()->shouldLog(LogComponent::kDefault,
- logger::LogSeverity::Debug(3));
+ shouldLog(LogComponent::kDefault, logger::LogSeverity::Debug(3));
}
});
stdx::thread setMinimumLoggedSeverityThreadA([&]() {
startupBarrier.countDownAndWait();
while (running.load()) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
- logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(LogComponent::kDefault, logger::LogSeverity::Debug(1));
}
});
stdx::thread setMinimumLoggedSeverityThreadB([&]() {
startupBarrier.countDownAndWait();
while (running.load()) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
- logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(LogComponent::kDefault, logger::LogSeverity::Log());
}
});
stdx::thread clearMinimumLoggedSeverityThread([&]() {
startupBarrier.countDownAndWait();
while (running.load()) {
- logger::globalLogDomain()->clearMinimumLoggedSeverity(LogComponent::kDefault);
+ clearMinimumLoggedSeverity(LogComponent::kDefault);
}
});
diff --git a/src/mongo/logger/log_function_test.cpp b/src/mongo/logger/log_function_test.cpp
index f05616161f5..dd4242dbe55 100644
--- a/src/mongo/logger/log_function_test.cpp
+++ b/src/mongo/logger/log_function_test.cpp
@@ -72,7 +72,7 @@ TEST_F(LogTestDetailsEncoder, LogFunctionsOverrideGlobalComponent) {
// severe() - with component.
_logLines.clear();
severe(componentA) << "This is logged";
- ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Severe()));
+ ASSERT_TRUE(shouldLog(componentA, LogSeverity::Severe()));
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " F " << componentA.getNameForLog()),
std::string::npos);
@@ -88,7 +88,7 @@ TEST_F(LogTestDetailsEncoder, LogFunctionsOverrideGlobalComponent) {
// error() - with component.
_logLines.clear();
error(componentA) << "This is logged";
- ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Error()));
+ ASSERT_TRUE(shouldLog(componentA, LogSeverity::Error()));
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " E " << componentA.getNameForLog()),
std::string::npos);
@@ -104,7 +104,7 @@ TEST_F(LogTestDetailsEncoder, LogFunctionsOverrideGlobalComponent) {
// warning() - with component.
_logLines.clear();
warning(componentA) << "This is logged";
- ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Warning()));
+ ASSERT_TRUE(shouldLog(componentA, LogSeverity::Warning()));
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " W " << componentA.getNameForLog()),
std::string::npos);
@@ -120,7 +120,7 @@ TEST_F(LogTestDetailsEncoder, LogFunctionsOverrideGlobalComponent) {
// log() - with component.
_logLines.clear();
log(componentA) << "This is logged";
- ASSERT_TRUE(logger::globalLogDomain()->shouldLog(componentA, LogSeverity::Log()));
+ ASSERT_TRUE(shouldLog(componentA, LogSeverity::Log()));
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " I " << componentA.getNameForLog()),
std::string::npos);
diff --git a/src/mongo/logger/log_test.cpp b/src/mongo/logger/log_test.cpp
index 9fb534a135f..3daf413bf9a 100644
--- a/src/mongo/logger/log_test.cpp
+++ b/src/mongo/logger/log_test.cpp
@@ -150,7 +150,7 @@ const LogComponent componentE = LogComponent::kJournal;
// Component severity configuration:
// LogComponent::kDefault: 2
TEST_F(LogTestUnadornedEncoder, MongoLogMacroNoFileScopeLogComponent) {
- globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(2));
+ setMinimumLoggedSeverity(LogSeverity::Debug(2));
LOG(2) << "This is logged";
LOG(3) << "This is not logged";
@@ -163,20 +163,6 @@ TEST_F(LogTestUnadornedEncoder, MongoLogMacroNoFileScopeLogComponent) {
MONGO_LOG_COMPONENT(3, componentA) << "This is not logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]);
-
- // MONGO_LOG_COMPONENT2
- _logLines.clear();
- MONGO_LOG_COMPONENT2(2, componentA, componentB) << "This is logged";
- MONGO_LOG_COMPONENT2(3, componentA, componentB) << "This is not logged";
- ASSERT_EQUALS(1U, _logLines.size());
- ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]);
-
- // MONGO_LOG_COMPONENT3
- _logLines.clear();
- MONGO_LOG_COMPONENT3(2, componentA, componentB, componentC) << "This is logged";
- MONGO_LOG_COMPONENT3(3, componentA, componentB, componentC) << "This is not logged";
- ASSERT_EQUALS(1U, _logLines.size());
- ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]);
}
//
@@ -239,8 +225,7 @@ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogDefaultLogComponent
// Set minimum logged severity so that Debug(1) messages are written to log domain.
settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
- LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
ASSERT_TRUE(shouldLog(LogSeverity::Info()));
ASSERT_TRUE(shouldLog(LogSeverity::Log()));
@@ -248,7 +233,7 @@ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogDefaultLogComponent
ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));
// Revert back.
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
+ setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
// Same results when components are supplied to shouldLog().
ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1)));
@@ -277,14 +262,13 @@ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogSingleComponent) {
ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2)));
// Test shouldLog() with global settings.
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
- LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
// Components for log message: LogComponent::kDefault only.
ASSERT_TRUE(shouldLog(LogSeverity::Debug(1)));
ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
+ setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
}
// Test for shouldLog() when we have configured multiple components.
@@ -314,15 +298,14 @@ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogMultipleComponentsC
ASSERT_FALSE(settings.shouldLog(componentC, LogSeverity::Debug(2)));
// Test shouldLog() with global settings.
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
- LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
// Components for log message: LogComponent::kDefault only.
ASSERT_TRUE(shouldLog(LogSeverity::Debug(1)));
ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));
- logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
+ setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
}
// Log component hierarchy.
@@ -424,7 +407,7 @@ TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogComponent) {
// Tests pass through of log component:
// log macros -> LogStreamBuilder -> MessageEventEphemeral -> MessageEventDetailsEncoder
TEST_F(LogTestDetailsEncoder, ) {
- globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Log());
+ setMinimumLoggedSeverity(LogSeverity::Log());
// Default log component short name should not appear in detailed log line.
MONGO_LOG_COMPONENT(0, componentDefault) << "This is logged";
@@ -437,21 +420,6 @@ TEST_F(LogTestDetailsEncoder, ) {
MONGO_LOG_COMPONENT(0, componentA) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()), std::string::npos);
-
- // MONGO_LOG_COMPONENT2 - only the first component is sent to LogStreamBuilder.
- _logLines.clear();
- MONGO_LOG_COMPONENT2(0, componentA, componentB) << "This is logged";
- ASSERT_EQUALS(1U, _logLines.size());
- ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()), std::string::npos);
- ASSERT_EQUALS(_logLines[0].find(componentB.getNameForLog().toString()), std::string::npos);
-
- // MONGO_LOG_COMPONENT3 - only the first component is sent to LogStreamBuilder.
- _logLines.clear();
- MONGO_LOG_COMPONENT3(0, componentA, componentB, componentC) << "This is logged";
- ASSERT_EQUALS(1U, _logLines.size());
- ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()), std::string::npos);
- ASSERT_EQUALS(_logLines[0].find(componentB.getNameForLog().toString()), std::string::npos);
- ASSERT_EQUALS(_logLines[0].find(componentC.getNameForLog().toString()), std::string::npos);
}
// Tests pass through of log component:
diff --git a/src/mongo/logger/log_test.h b/src/mongo/logger/log_test.h
index 644973739b2..a5e8d914454 100644
--- a/src/mongo/logger/log_test.h
+++ b/src/mongo/logger/log_test.h
@@ -39,6 +39,7 @@
#include "mongo/logger/logger.h"
#include "mongo/logger/message_log_domain.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log_global_settings.h"
namespace mongo {
namespace logger {
@@ -51,7 +52,7 @@ class LogTest : public unittest::Test {
friend class LogTestAppender;
public:
- LogTest() : _severityOld(globalLogDomain()->getMinimumLogSeverity()) {
+ LogTest() : _severityOld(getMinimumLogSeverity()) {
globalLogDomain()->clearAppenders();
_appenderHandle =
globalLogDomain()->attachAppender(std::make_unique<LogTestAppender>(this));
@@ -59,7 +60,7 @@ public:
virtual ~LogTest() {
globalLogDomain()->detachAppender(_appenderHandle);
- globalLogDomain()->setMinimumLoggedSeverity(_severityOld);
+ setMinimumLoggedSeverity(_severityOld);
}
protected:
diff --git a/src/mongo/logger/logv2_appender.h b/src/mongo/logger/logv2_appender.h
index d728cdf780f..e5a677099cb 100644
--- a/src/mongo/logger/logv2_appender.h
+++ b/src/mongo/logger/logv2_appender.h
@@ -32,6 +32,7 @@
#include "mongo/base/status.h"
#include "mongo/logger/appender.h"
#include "mongo/logger/log_version_util.h"
+#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logv2/log_component.h"
#include "mongo/logv2/log_detail.h"
#include "mongo/logv2/log_domain.h"
@@ -73,6 +74,27 @@ public:
Status append(const Event& event) override {
auto logTagValue = findTeeTag(event.getTeeName());
+ auto message = event.getMessage();
+ if (message.endsWith("\n")) {
+ message = message.substr(0, message.size() - 1);
+ }
+ size_t maxSizeKB = MessageEventDetailsEncoder::getMaxLogSizeKB();
+
+ if (event.isTruncatable() && message.size() > maxSizeKB * 1024) {
+ logv2::detail::doLog(
+ logv2::LogSeverity::cast(event.getSeverity().toInt()),
+ StringData{},
+ logv2::LogOptions{
+ logComponentV1toV2(event.getComponent()),
+ _domain,
+ logv2::LogTag{static_cast<logv2::LogTag::Value>(
+ static_cast<std::underlying_type_t<logv2::LogTag::Value>>(logTagValue) |
+ static_cast<std::underlying_type_t<logv2::LogTag::Value>>(_tag))}},
+
+ "warning: log line attempted ({}kB) over max size ({}kB)",
+ "size"_attr = message.size() / 1024,
+ "maxSize"_attr = maxSizeKB);
+ }
logv2::detail::doLog(
@@ -92,7 +114,7 @@ public:
static_cast<std::underlying_type_t<logv2::LogTag::Value>>(_tag))}},
"{}",
- "message"_attr = event.getMessage());
+ "message"_attr = message);
return Status::OK();
}
diff --git a/src/mongo/rpc/op_msg_test.cpp b/src/mongo/rpc/op_msg_test.cpp
index 2698cd3e39e..c534dbdb702 100644
--- a/src/mongo/rpc/op_msg_test.cpp
+++ b/src/mongo/rpc/op_msg_test.cpp
@@ -160,14 +160,11 @@ public:
class OpMsgParser : public unittest::Test {
public:
void setUp() override {
- _original =
- logger::globalLogDomain()->getMinimumLogSeverity(logger::LogComponent::kNetwork);
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kNetwork,
- logger::LogSeverity::Debug(1));
+ _original = getMinimumLogSeverity(logger::LogComponent::kNetwork);
+ setMinimumLoggedSeverity(logger::LogComponent::kNetwork, logger::LogSeverity::Debug(1));
}
void tearDown() override {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kNetwork,
- _original);
+ setMinimumLoggedSeverity(logger::LogComponent::kNetwork, _original);
}
private:
diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp
index 349b3976f06..c28a962636b 100644
--- a/src/mongo/s/client/shard_remote.cpp
+++ b/src/mongo/s/client/shard_remote.cpp
@@ -163,9 +163,8 @@ std::string ShardRemote::toString() const {
BSONObj ShardRemote::_appendMetadataForCommand(OperationContext* opCtx,
const ReadPreferenceSetting& readPref) {
BSONObjBuilder builder;
- if (logger::globalLogDomain()->shouldLog(
- logger::LogComponent::kTracking,
- logger::LogSeverity::Debug(1))) { // avoid performance overhead if not logging
+ if (shouldLog(logger::LogComponent::kTracking,
+ logger::LogSeverity::Debug(1))) { // avoid performance overhead if not logging
if (!TrackingMetadata::get(opCtx).getIsLogged()) {
if (!TrackingMetadata::get(opCtx).getOperId()) {
TrackingMetadata::get(opCtx).initWithOperName("NotSet");
diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp
index 3a552ddc1b4..a54f7cf1fbe 100644
--- a/src/mongo/s/mongos_options.cpp
+++ b/src/mongo/s/mongos_options.cpp
@@ -68,8 +68,7 @@ bool handlePreValidationMongosOptions(const moe::Environment& params,
return false;
}
if (params.count("test") && params["test"].as<bool>() == true) {
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Debug(5));
+ setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Debug(5));
return false;
}
diff --git a/src/mongo/s/transaction_router_test.cpp b/src/mongo/s/transaction_router_test.cpp
index 8a2ab13aefb..5dcffc859cf 100644
--- a/src/mongo/s/transaction_router_test.cpp
+++ b/src/mongo/s/transaction_router_test.cpp
@@ -3132,16 +3132,14 @@ TEST_F(TransactionRouterMetricsTest, OnlyLogSlowTransactionsOnce) {
TEST_F(TransactionRouterMetricsTest, NoTransactionsLoggedAtDefaultTransactionLogLevel) {
// Set verbosity level of transaction components to the default, i.e. debug level 0.
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
beginTxnWithDefaultTxnNumber();
runSingleShardCommit();
assertDidNotPrintSlowLogLine();
}
TEST_F(TransactionRouterMetricsTest, AllTransactionsLoggedAtTransactionLogLevelOne) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kTransaction,
- logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Debug(1));
beginTxnWithDefaultTxnNumber();
runSingleShardCommit();
assertPrintedExactlyOneSlowLogLine();
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index eca95ae9f92..3e59edfbfb1 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -749,7 +749,7 @@ int _main(int argc, char* argv[], char** envp) {
if (!mongo::serverGlobalParams.quiet.load())
std::cout << mongoShellVersion(VersionInfoInterface::instance()) << std::endl;
- if (!shellGlobalParams.logV2) {
+ if (!logV2Enabled()) {
logger::globalLogManager()
->getNamedDomain("javascriptOutput")
->attachAppender(std::make_unique<ShellConsoleAppender>(
diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp
index 2441ff9ce45..7f0766c3496 100644
--- a/src/mongo/shell/shell_options.cpp
+++ b/src/mongo/shell/shell_options.cpp
@@ -109,7 +109,7 @@ Status storeMongoShellOptions(const moe::Environment& params,
}
if (params.count("verbose")) {
- logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
}
// `objcheck` option is part of `serverGlobalParams` to avoid making common parts depend upon
@@ -338,7 +338,7 @@ Status storeMongoShellOptions(const moe::Environment& params,
}
if (params.count("logv2")) {
- shellGlobalParams.logV2 = true;
+ logV2Set(true);
}
return Status::OK();
diff --git a/src/mongo/shell/shell_options.h b/src/mongo/shell/shell_options.h
index 2868998197f..45ac4e55455 100644
--- a/src/mongo/shell/shell_options.h
+++ b/src/mongo/shell/shell_options.h
@@ -81,8 +81,6 @@ struct ShellGlobalParams {
int jsHeapLimitMB = 0;
bool nokillop = false;
Seconds idleSessionTimeout = Seconds{0};
-
- bool logV2 = false;
};
extern ShellGlobalParams shellGlobalParams;
diff --git a/src/mongo/tools/mongobridge_options.cpp b/src/mongo/tools/mongobridge_options.cpp
index 81a116df714..af1aee5fba6 100644
--- a/src/mongo/tools/mongobridge_options.cpp
+++ b/src/mongo/tools/mongobridge_options.cpp
@@ -81,8 +81,7 @@ Status storeMongoBridgeOptions(const moe::Environment& params,
return {ErrorCodes::BadValue,
"The string for the --verbose option cannot contain characters other than 'v'"};
}
- logger::globalLogDomain()->setMinimumLoggedSeverity(
- logger::LogSeverity::Debug(verbosity.length()));
+ setMinimumLoggedSeverity(logger::LogSeverity::Debug(verbosity.length()));
}
return Status::OK();
diff --git a/src/mongo/unittest/unittest_main.cpp b/src/mongo/unittest/unittest_main.cpp
index 7cc6918ebe6..8c02e03ebc0 100644
--- a/src/mongo/unittest/unittest_main.cpp
+++ b/src/mongo/unittest/unittest_main.cpp
@@ -36,6 +36,7 @@
#include "mongo/logger/logger.h"
#include "mongo/unittest/unittest.h"
#include "mongo/unittest/unittest_options_gen.h"
+#include "mongo/util/log_global_settings.h"
#include "mongo/util/options_parser/environment.h"
#include "mongo/util/options_parser/option_section.h"
#include "mongo/util/options_parser/options_parser.h"
@@ -88,8 +89,7 @@ int main(int argc, char** argv, char** envp) {
std::cerr << options.helpString();
return EXIT_FAILURE;
}
- ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
- ::mongo::logger::LogSeverity::Debug(verbose.length()));
+ mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Debug(verbose.length()));
if (list) {
auto suiteNames = ::mongo::unittest::getAllSuiteNames();
diff --git a/src/mongo/util/log.cpp b/src/mongo/util/log.cpp
index ce127933ece..4bafb18d952 100644
--- a/src/mongo/util/log.cpp
+++ b/src/mongo/util/log.cpp
@@ -35,6 +35,7 @@
#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"
@@ -54,6 +55,20 @@
namespace mongo {
+#if MONGO_CONFIG_LOGV2_BUILD
+static bool _logV2Enabled = true;
+#else
+static bool _logV2Enabled = false;
+#endif
+
+bool logV2Enabled() {
+ return _logV2Enabled;
+}
+
+void logV2Set(bool setting) {
+ _logV2Enabled = setting;
+}
+
static logger::ExtraLogContextFn _appendExtraLogContext;
Status logger::registerExtraLogContextFn(logger::ExtraLogContextFn contextFn) {
diff --git a/src/mongo/util/log.h b/src/mongo/util/log.h
index 24a321892e4..145b41c5a6f 100644
--- a/src/mongo/util/log.h
+++ b/src/mongo/util/log.h
@@ -46,14 +46,19 @@
#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/redaction.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 {
@@ -167,24 +172,20 @@ inline LogstreamBuilder log(logger::LogComponent::Value componentValue) {
logger::globalLogDomain(), getThreadName(), logger::LogSeverity::Log(), componentValue);
}
-/**
- * Runs the same logic as log()/warning()/error(), without actually outputting a stream.
- */
-inline bool shouldLog(logger::LogComponent logComponent, logger::LogSeverity severity) {
- return logger::globalLogDomain()->shouldLog(logComponent, severity);
-}
+} // namespace
+// this can't be in log_global_settings.h because it utilizes MongoLogDefaultComponent_component
inline bool shouldLog(logger::LogSeverity severity) {
- return shouldLog(MongoLogDefaultComponent_component, severity);
+ if (logV2Enabled())
+ return logv2::LogManager::global().getGlobalSettings().shouldLog(
+ logComponentV1toV2(MongoLogDefaultComponent_component), logSeverityV1toV2(severity));
+ return mongo::shouldLog(MongoLogDefaultComponent_component, severity);
}
-} // namespace
-
// MONGO_LOG uses log component from MongoLogDefaultComponent from current or global namespace.
#define MONGO_LOG(DLEVEL) \
- if (!(::mongo::logger::globalLogDomain()) \
- ->shouldLog(MongoLogDefaultComponent_component, \
- ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
+ if (!::mongo::shouldLog(MongoLogDefaultComponent_component, \
+ ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
} else \
::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
::mongo::getThreadName(), \
@@ -193,36 +194,14 @@ inline bool shouldLog(logger::LogSeverity severity) {
#define LOG MONGO_LOG
-#define MONGO_LOG_COMPONENT(DLEVEL, COMPONENT1) \
- if (!(::mongo::logger::globalLogDomain()) \
- ->shouldLog((COMPONENT1), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
- } else \
- ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
- ::mongo::getThreadName(), \
- ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
- (COMPONENT1))
-
-#define MONGO_LOG_COMPONENT2(DLEVEL, COMPONENT1, COMPONENT2) \
- if (!(::mongo::logger::globalLogDomain()) \
- ->shouldLog( \
- (COMPONENT1), (COMPONENT2), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
- } else \
- ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
- ::mongo::getThreadName(), \
- ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
+#define MONGO_LOG_COMPONENT(DLEVEL, COMPONENT1) \
+ if (!::mongo::shouldLog((COMPONENT1), ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
+ } else \
+ ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
+ ::mongo::getThreadName(), \
+ ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
(COMPONENT1))
-#define MONGO_LOG_COMPONENT3(DLEVEL, COMPONENT1, COMPONENT2, COMPONENT3) \
- if (!(::mongo::logger::globalLogDomain()) \
- ->shouldLog((COMPONENT1), \
- (COMPONENT2), \
- (COMPONENT3), \
- ::mongo::LogstreamBuilder::severityCast(DLEVEL))) { \
- } else \
- ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
- ::mongo::getThreadName(), \
- ::mongo::LogstreamBuilder::severityCast(DLEVEL), \
- (COMPONENT1))
/**
* Rotates the log files. Returns true if all logs rotate successfully.
diff --git a/src/mongo/util/log_global_settings.h b/src/mongo/util/log_global_settings.h
new file mode 100644
index 00000000000..79e3f177580
--- /dev/null
+++ b/src/mongo/util/log_global_settings.h
@@ -0,0 +1,101 @@
+/**
+ * Copyright (C) 2019-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.
+ */
+
+#pragma once
+
+#include "mongo/base/status.h"
+#include "mongo/logger/log_component.h"
+#include "mongo/logger/log_severity_limiter.h"
+#include "mongo/logger/log_version_util.h"
+#include "mongo/logger/logger.h"
+#include "mongo/logv2/log_component.h"
+#include "mongo/logv2/log_component_settings.h"
+#include "mongo/logv2/log_manager.h"
+
+namespace mongo {
+
+bool logV2Enabled();
+void logV2Set(bool setting);
+
+/**
+ * Runs the same logic as log()/warning()/error(), without actually outputting a stream.
+ */
+
+inline bool shouldLog(logger::LogComponent logComponent1, logger::LogSeverity severity) {
+ if (logV2Enabled())
+ return logv2::LogManager::global().getGlobalSettings().shouldLog(
+ logComponentV1toV2(logComponent1), logSeverityV1toV2(severity));
+ return logger::globalLogDomain()->shouldLog(logComponent1, severity);
+}
+
+inline logger::LogSeverity getMinimumLogSeverity() {
+ if (logV2Enabled())
+ return logSeverityV2toV1(
+ logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(
+ mongo::logv2::LogComponent::kDefault));
+ return logger::globalLogDomain()->getMinimumLogSeverity();
+}
+
+inline logger::LogSeverity getMinimumLogSeverity(logger::LogComponent component) {
+ if (logV2Enabled())
+ return logSeverityV2toV1(
+ logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(
+ logComponentV1toV2(component)));
+ return logger::globalLogDomain()->getMinimumLogSeverity(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);
+}
+
+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);
+}
+
+inline void clearMinimumLoggedSeverity(logger::LogComponent component) {
+ if (logV2Enabled())
+ return logv2::LogManager::global().getGlobalSettings().clearMinimumLoggedSeverity(
+ logComponentV1toV2(component));
+ logger::globalLogDomain()->clearMinimumLoggedSeverity(component);
+}
+
+inline bool hasMinimumLogSeverity(logger::LogComponent component) {
+ if (logV2Enabled())
+ return logv2::LogManager::global().getGlobalSettings().hasMinimumLogSeverity(
+ logComponentV1toV2(component));
+ return logger::globalLogDomain()->hasMinimumLogSeverity(component);
+}
+
+} // namespace mongo
diff --git a/src/mongo/util/signal_handlers.cpp b/src/mongo/util/signal_handlers.cpp
index eb1ae13d6ea..fac8d57da1e 100644
--- a/src/mongo/util/signal_handlers.cpp
+++ b/src/mongo/util/signal_handlers.cpp
@@ -187,8 +187,7 @@ void signalProcessingThread(LogFileStatus rotate) {
}
lastSignalTimeSeconds = signalTimeSeconds;
- fassert(16782,
- rotateLogs(serverGlobalParams.logRenameOnRotate, serverGlobalParams.logV2));
+ fassert(16782, rotateLogs(serverGlobalParams.logRenameOnRotate, logV2Enabled()));
if (rotate == LogFileStatus::kNeedToRotateLogFile) {
logProcessDetailsForLogRotate(getGlobalServiceContext());
}