summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2020-02-26 22:58:46 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-27 19:23:39 +0000
commitff724b466d7bc7ead68eacd5524cc1185b8b4523 (patch)
treeab550e052883eb26ad7321663cb2f6066e43ce28 /src/mongo
parent9a421e19cef1caa2627d4776db700ae5c8751932 (diff)
downloadmongo-ff724b466d7bc7ead68eacd5524cc1185b8b4523.tar.gz
SERVER-46405 Remove {get,set,clear}MinimumLoggedSeverity from logger V1 API
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/parameters.cpp34
-rw-r--r--src/mongo/db/repl/apply_ops_test.cpp5
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp5
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp13
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp3
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp9
-rw-r--r--src/mongo/db/repl/rollback_test_fixture.cpp8
-rw-r--r--src/mongo/db/repl/topology_coordinator_v1_test.cpp5
-rw-r--r--src/mongo/db/s/transaction_coordinator_test.cpp11
-rw-r--r--src/mongo/db/server_options_helpers.cpp15
-rw-r--r--src/mongo/db/server_options_test.cpp79
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp5
-rw-r--r--src/mongo/db/transaction_participant_test.cpp7
-rw-r--r--src/mongo/dbtests/framework_options.cpp3
-rw-r--r--src/mongo/logger/log_component_settings_test.cpp1
-rw-r--r--src/mongo/logger/log_test.h47
-rw-r--r--src/mongo/logv2/log_component.cpp4
-rw-r--r--src/mongo/logv2/log_component.h2
-rw-r--r--src/mongo/logv2/log_severity.h2
-rw-r--r--src/mongo/rpc/op_msg_test.cpp9
-rw-r--r--src/mongo/s/mongos_options.cpp4
-rw-r--r--src/mongo/s/transaction_router_test.cpp5
-rw-r--r--src/mongo/shell/shell_options.cpp3
-rw-r--r--src/mongo/tools/mongobridge_options.cpp6
-rw-r--r--src/mongo/unittest/log_test.h66
-rw-r--r--src/mongo/unittest/unittest_main.cpp3
-rw-r--r--src/mongo/util/log_global_settings.h44
-rw-r--r--src/mongo/util/log_with_sampling.h1
-rw-r--r--src/mongo/util/log_with_sampling_test.cpp51
29 files changed, 271 insertions, 179 deletions
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index 2b89a29b21f..7cb02d02e58 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -42,10 +42,8 @@
#include "mongo/db/commands.h"
#include "mongo/db/commands/parameters_gen.h"
#include "mongo/db/storage/storage_options.h"
-#include "mongo/logger/logger.h"
#include "mongo/logger/parse_log_component_settings.h"
#include "mongo/logv2/log.h"
-#include "mongo/util/log.h"
#include "mongo/util/str.h"
using std::string;
@@ -54,11 +52,10 @@ using std::stringstream;
namespace mongo {
namespace {
-using logger::globalLogDomain;
-using logger::LogComponent;
using logger::LogComponentSetting;
-using logger::LogSeverity;
using logger::parseLogComponentSettings;
+using logv2::LogComponent;
+using logv2::LogSeverity;
void appendParameterNames(std::string* help) {
*help += "supported:\n";
@@ -102,8 +99,11 @@ void getLogComponentVerbosity(BSONObj* output) {
LogComponent component = static_cast<LogComponent::Value>(i);
int severity = -1;
- if (hasMinimumLogSeverity(component)) {
- severity = getMinimumLogSeverity(component).toInt();
+ if (logv2::LogManager::global().getGlobalSettings().hasMinimumLogSeverity(component)) {
+ severity = logv2::LogManager::global()
+ .getGlobalSettings()
+ .getMinimumLogSeverity(component)
+ .toInt();
}
// Save LogComponent::kDefault LogSeverity at root
@@ -173,13 +173,15 @@ Status setLogComponentVerbosity(const BSONObj& bsonSettings) {
// Negative value means to clear log level of component.
if (newSetting.level < 0) {
- clearMinimumLoggedSeverity(newSetting.component);
+ logv2::LogManager::global().getGlobalSettings().clearMinimumLoggedSeverity(
+ logComponentV1toV2(newSetting.component));
continue;
}
// Convert non-negative value to Log()/Debug(N).
LogSeverity newSeverity =
(newSetting.level > 0) ? LogSeverity::Debug(newSetting.level) : LogSeverity::Log();
- setMinimumLoggedSeverity(newSetting.component, newSeverity);
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ logComponentV1toV2(newSetting.component), newSeverity);
}
return Status::OK();
@@ -396,7 +398,11 @@ public:
void LogLevelServerParameter::append(OperationContext*,
BSONObjBuilder& builder,
const std::string& name) {
- builder.append(name, getMinimumLogSeverity().toInt());
+ builder.append(name,
+ logv2::LogManager::global()
+ .getGlobalSettings()
+ .getMinimumLogSeverity(mongo::logv2::LogComponent::kDefault)
+ .toInt());
}
Status LogLevelServerParameter::set(const BSONElement& newValueElement) {
@@ -405,7 +411,9 @@ 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();
- setMinimumLoggedSeverity(newSeverity);
+
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, newSeverity);
return Status::OK();
}
@@ -418,7 +426,9 @@ 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();
- setMinimumLoggedSeverity(newSeverity);
+
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, newSeverity);
return Status::OK();
}
diff --git a/src/mongo/db/repl/apply_ops_test.cpp b/src/mongo/db/repl/apply_ops_test.cpp
index 85c4c428361..65e8c3f7435 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/unittest/log_test.h"
#include "mongo/util/log_global_settings.h"
namespace mongo {
@@ -116,7 +117,7 @@ void ApplyOpsTest::tearDown() {
_opObserver = nullptr;
// Reset default log level in case it was changed.
- setMinimumLoggedSeverity(logger::LogComponent::kReplication, logger::LogSeverity::Debug(0));
+ setMinimumLoggedSeverity(logv2::LogComponent::kReplication, logv2::LogSeverity::Debug(0));
ServiceContextMongoDTest::tearDown();
}
@@ -290,7 +291,7 @@ TEST_F(ApplyOpsTest, ApplyOpsPropagatesOplogApplicationMode) {
auto opCtx = cc().makeOperationContext();
// Increase log component verbosity to check for op application messages.
- setMinimumLoggedSeverity(logger::LogComponent::kReplication, logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogComponent::kReplication, logv2::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 59db90faba0..e39c06ef556 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
@@ -45,6 +45,7 @@
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/executor/network_interface_mock.h"
#include "mongo/logv2/log.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -534,7 +535,7 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) {
ASSERT_EQUALS(ErrorCodes::ConfigurationInProgress,
getReplCoord()->processReplSetReconfig(&opCtx, args, &result));
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(2));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(2));
startCapturingLogMessages();
// receive sufficient heartbeats to allow the node to see a majority.
@@ -1144,7 +1145,7 @@ TEST_F(TakeoverTest, PrefersPriorityToCatchupTakeoverIfNodeHasHighestPriority) {
<< "node3:12345"))
<< "protocolVersion" << 1);
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(2));
+ setMinimumLoggedSeverity(logv2::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 27271617d88..4313fa2edb1 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
@@ -43,6 +43,7 @@
#include "mongo/executor/network_interface_mock.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -87,7 +88,7 @@ ReplSetHeartbeatResponse ReplCoordHBV1Test::receiveHeartbeatFrom(const ReplSetCo
TEST_F(ReplCoordHBV1Test,
NodeJoinsExistingReplSetWhenReceivingAConfigContainingTheNodeViaHeartbeat) {
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id"
<< "mySet"
<< "version" << 3 << "members"
@@ -157,7 +158,7 @@ TEST_F(ReplCoordHBV1Test,
class ReplCoordHBV1ReconfigTest : public ReplCoordHBV1Test {
public:
void setUp() {
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
BSONObj configBson = BSON("_id"
<< "mySet"
<< "version" << initConfigVersion << "term" << initConfigTerm
@@ -498,7 +499,7 @@ TEST_F(ReplCoordHBV1Test, AwaitIsMasterReturnsResponseOnReconfigViaHeartbeat) {
ASSERT_EQUALS("node3", hosts[2].host());
});
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
ReplSetConfig rsConfig =
assertMakeRSConfig(BSON("_id"
<< "mySet"
@@ -549,7 +550,7 @@ TEST_F(ReplCoordHBV1Test, AwaitIsMasterReturnsResponseOnReconfigViaHeartbeat) {
TEST_F(ReplCoordHBV1Test,
ArbiterJoinsExistingReplSetWhenReceivingAConfigContainingTheArbiterViaHeartbeat) {
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
ReplSetConfig rsConfig =
assertMakeRSConfig(BSON("_id"
<< "mySet"
@@ -622,7 +623,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.
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id"
<< "mySet"
<< "version" << 3 << "members"
@@ -704,7 +705,7 @@ TEST_F(ReplCoordHBV1Test,
TEST_F(ReplCoordHBV1Test,
NodeChangesToRecoveringStateWhenAllNodesRespondToHeartbeatsWithUnauthorized) {
// Tests that a node that only has auth error heartbeats is recovering
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::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 29ce2ceb1a8..73832a41225 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/repl/replication_coordinator_impl.h"
#include "mongo/db/repl/replication_coordinator_test_fixture.h"
#include "mongo/executor/network_interface_mock.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -687,7 +688,7 @@ TEST_F(ReplCoordTest, NodeAcceptsConfigFromAReconfigWithForceTrueWhileNotPrimary
class ReplCoordReconfigTest : public ReplCoordTest {
public:
void setUp() {
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
}
BSONObj member(int id, std::string host) {
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index fd4b5257693..1f4e4c4b930 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -71,6 +71,7 @@
#include "mongo/unittest/barrier.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/ensure_fcv.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -6147,8 +6148,8 @@ TEST_F(ReplCoordTest,
TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) {
// Log all the election messages.
- setMinimumLoggedSeverity(logger::LogComponent::kReplicationElection,
- logger::LogSeverity::Debug(5));
+ setMinimumLoggedSeverity(logv2::LogComponent::kReplicationElection,
+ logv2::LogSeverity::Debug(5));
startCapturingLogMessages();
// heartbeatTimeoutSecs is made large so we can advance the clock without worrying about
// additional heartbeats.
@@ -6207,8 +6208,8 @@ TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) {
ASSERT_EQ(1, countTextFormatLogLinesContaining("Rescheduling election timeout callback"));
ASSERT_EQ(1, countTextFormatLogLinesContaining("Canceling election timeout callback"));
- setMinimumLoggedSeverity(logger::LogComponent::kReplicationElection,
- logger::LogSeverity::Debug(4));
+ setMinimumLoggedSeverity(logv2::LogComponent::kReplicationElection,
+ logv2::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 f73902f7a38..6f17ac16717 100644
--- a/src/mongo/db/repl/rollback_test_fixture.cpp
+++ b/src/mongo/db/repl/rollback_test_fixture.cpp
@@ -48,9 +48,7 @@
#include "mongo/db/repl/replication_recovery.h"
#include "mongo/db/repl/rs_rollback.h"
#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/unittest/log_test.h"
#include "mongo/util/str.h"
namespace mongo {
@@ -113,8 +111,8 @@ void RollbackTest::setUp() {
_replicationProcess->initializeRollbackID(_opCtx.get()).transitional_ignore();
// Increase rollback log component verbosity for unit tests.
- setMinimumLoggedSeverity(logger::LogComponent::kReplicationRollback,
- logger::LogSeverity::Debug(2));
+ setMinimumLoggedSeverity(logv2::LogComponent::kReplicationRollback,
+ logv2::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_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
index 8bf6c04c710..79f65c89259 100644
--- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
@@ -48,6 +48,7 @@
#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log_global_settings.h"
@@ -6398,12 +6399,12 @@ public:
virtual void setUp() {
HeartbeatResponseTestV1::setUp();
// set verbosity as high as the highest verbosity log message we'd like to check for
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
}
virtual void tearDown() {
HeartbeatResponseTestV1::tearDown();
- setMinimumLoggedSeverity(logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logv2::LogSeverity::Log());
}
};
diff --git a/src/mongo/db/s/transaction_coordinator_test.cpp b/src/mongo/db/s/transaction_coordinator_test.cpp
index 3d6be9ff152..cc312d67f1f 100644
--- a/src/mongo/db/s/transaction_coordinator_test.cpp
+++ b/src/mongo/db/s/transaction_coordinator_test.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/s/transaction_coordinator_metrics_observer.h"
#include "mongo/db/s/transaction_coordinator_test_fixture.h"
#include "mongo/logv2/log.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/log.h"
@@ -2113,13 +2114,13 @@ TEST_F(TransactionCoordinatorMetricsTest, CoordinatorsAWSIsShutDownWhileCoordina
}
TEST_F(TransactionCoordinatorMetricsTest, LogsTransactionAtLogLevelOne) {
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Debug(1));
runSimpleTwoPhaseCommitWithCommitDecisionAndCaptureLogLines();
ASSERT_EQUALS(1, countTextFormatLogLinesContaining("two-phase commit parameters:"));
}
TEST_F(TransactionCoordinatorMetricsTest, DoesNotLogTransactionAtLogLevelZero) {
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Log());
runSimpleTwoPhaseCommitWithCommitDecisionAndCaptureLogLines();
ASSERT_EQUALS(0, countTextFormatLogLinesContaining("two-phase commit parameters:"));
}
@@ -2127,7 +2128,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.
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Log());
serverGlobalParams.slowMS = 100;
startCapturingLogMessages();
@@ -2158,7 +2159,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.
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Log());
serverGlobalParams.slowMS = 100;
startCapturingLogMessages();
@@ -2187,7 +2188,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.
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Log());
serverGlobalParams.slowMS = 100;
startCapturingLogMessages();
diff --git a/src/mongo/db/server_options_helpers.cpp b/src/mongo/db/server_options_helpers.cpp
index 802c9726622..ba592b4eaa6 100644
--- a/src/mongo/db/server_options_helpers.cpp
+++ b/src/mongo/db/server_options_helpers.cpp
@@ -274,13 +274,14 @@ Status storeBaseOptions(const moe::Environment& params) {
return Status(ErrorCodes::BadValue,
"systemLog.verbosity YAML Config cannot be negative");
}
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(verbosity));
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, logv2::LogSeverity::Debug(verbosity));
}
// log component hierarchy verbosity levels
- for (int i = 0; i < int(logger::LogComponent::kNumLogComponents); ++i) {
- logger::LogComponent component = static_cast<logger::LogComponent::Value>(i);
- if (component == logger::LogComponent::kDefault) {
+ for (int i = 0; i < int(logv2::LogComponent::kNumLogComponents); ++i) {
+ logv2::LogComponent component = static_cast<logv2::LogComponent::Value>(i);
+ if (component == logv2::LogComponent::kDefault) {
continue;
}
const string dottedName = "systemLog.component." + component.getDottedName() + ".verbosity";
@@ -288,9 +289,11 @@ Status storeBaseOptions(const moe::Environment& params) {
int verbosity = params[dottedName].as<int>();
// Clear existing log level if log level is negative.
if (verbosity < 0) {
- clearMinimumLoggedSeverity(component);
+ logv2::LogManager::global().getGlobalSettings().clearMinimumLoggedSeverity(
+ component);
} else {
- setMinimumLoggedSeverity(component, logger::LogSeverity::Debug(verbosity));
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ component, logv2::LogSeverity::Debug(verbosity));
}
}
}
diff --git a/src/mongo/db/server_options_test.cpp b/src/mongo/db/server_options_test.cpp
index 5eb7600696b..bb70d61bd1e 100644
--- a/src/mongo/db/server_options_test.cpp
+++ b/src/mongo/db/server_options_test.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/server_options_nongeneral_gen.h"
#include "mongo/db/server_options_server_helpers.h"
#include "mongo/logger/logger.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
#include "mongo/util/options_parser/environment.h"
@@ -102,7 +103,7 @@ TEST(Verbosity, Default) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -118,7 +119,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::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Info());
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Info());
}
TEST(Verbosity, CommandLineImplicit) {
@@ -127,7 +128,7 @@ TEST(Verbosity, CommandLineImplicit) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -144,7 +145,7 @@ TEST(Verbosity, CommandLineImplicit) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 1;
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, CommandLineString) {
@@ -153,7 +154,7 @@ TEST(Verbosity, CommandLineString) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -171,7 +172,7 @@ TEST(Verbosity, CommandLineString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, CommandLineStringDisguisedLongForm) {
@@ -180,7 +181,7 @@ TEST(Verbosity, CommandLineStringDisguisedLongForm) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -198,7 +199,7 @@ TEST(Verbosity, CommandLineStringDisguisedLongForm) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, CommandLineEmptyString) {
@@ -207,7 +208,7 @@ TEST(Verbosity, CommandLineEmptyString) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -226,7 +227,7 @@ TEST(Verbosity, CommandLineBadString) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -247,7 +248,7 @@ TEST(Verbosity, CommandLineBadStringOnlyDash) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -265,7 +266,7 @@ TEST(Verbosity, CommandLineBadStringOnlyTwoDashes) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -283,7 +284,7 @@ TEST(Verbosity, INIConfigString) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -303,7 +304,7 @@ TEST(Verbosity, INIConfigString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, INIConfigBadString) {
@@ -312,7 +313,7 @@ TEST(Verbosity, INIConfigBadString) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -335,7 +336,7 @@ TEST(Verbosity, INIConfigEmptyString) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -355,7 +356,7 @@ TEST(Verbosity, INIConfigEmptyString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 0;
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, JSONConfigString) {
@@ -364,7 +365,7 @@ TEST(Verbosity, JSONConfigString) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -384,7 +385,7 @@ TEST(Verbosity, JSONConfigString) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 4;
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, MultipleSourcesMultipleOptions) {
@@ -393,7 +394,7 @@ TEST(Verbosity, MultipleSourcesMultipleOptions) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -415,7 +416,7 @@ TEST(Verbosity, MultipleSourcesMultipleOptions) {
ASSERT_OK(::mongo::storeServerOptions(environment));
int verbosity = 3;
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
}
TEST(Verbosity, YAMLConfigStringLogComponent) {
@@ -424,10 +425,10 @@ TEST(Verbosity, YAMLConfigStringLogComponent) {
moe::OptionSection options;
// Reset the log level before we test
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Info());
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Info());
// Log level for Storage will be cleared by config file value.
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogComponent::kStorage,
- ::mongo::logger::LogSeverity::Debug(1));
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogComponent::kStorage,
+ ::mongo::logv2::LogSeverity::Debug(1));
ASSERT_OK(::mongo::addGeneralServerOptions(&options));
@@ -459,29 +460,29 @@ TEST(Verbosity, YAMLConfigStringLogComponent) {
int verbosity = 4;
// Default
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logger::LogSeverity::Debug(verbosity));
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kDefault),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(), ::mongo::logv2::LogSeverity::Debug(verbosity));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logv2::LogComponent::kDefault),
+ ::mongo::logv2::LogSeverity::Debug(verbosity));
// AccessControl
- ASSERT_TRUE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kAccessControl));
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kAccessControl),
- ::mongo::logger::LogSeverity::Log());
+ ASSERT_TRUE(mongo::hasMinimumLogSeverity(::mongo::logv2::LogComponent::kAccessControl));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logv2::LogComponent::kAccessControl),
+ ::mongo::logv2::LogSeverity::Log());
// Query - not mentioned in configuration. should match default.
- ASSERT_FALSE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kStorage));
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kStorage),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_FALSE(mongo::hasMinimumLogSeverity(::mongo::logv2::LogComponent::kStorage));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logv2::LogComponent::kStorage),
+ ::mongo::logv2::LogSeverity::Debug(verbosity));
// Storage - cleared by -1 value in configuration. should match default.
- ASSERT_FALSE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kStorage));
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kStorage),
- ::mongo::logger::LogSeverity::Debug(verbosity));
+ ASSERT_FALSE(mongo::hasMinimumLogSeverity(::mongo::logv2::LogComponent::kStorage));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logv2::LogComponent::kStorage),
+ ::mongo::logv2::LogSeverity::Debug(verbosity));
// Journaling - explicitly set to 2 in configuration.
- ASSERT_TRUE(mongo::hasMinimumLogSeverity(::mongo::logger::LogComponent::kJournal));
- ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logger::LogComponent::kJournal),
- ::mongo::logger::LogSeverity::Debug(2));
+ ASSERT_TRUE(mongo::hasMinimumLogSeverity(::mongo::logv2::LogComponent::kJournal));
+ ASSERT_EQUALS(mongo::getMinimumLogSeverity(::mongo::logv2::LogComponent::kJournal),
+ ::mongo::logv2::LogSeverity::Debug(2));
}
TEST(SetupOptions, Default) {
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 35565f41cee..d0e8a07a59b 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/db/storage/wiredtiger/wiredtiger_record_store.h"
#include "mongo/logger/logger.h"
#include "mongo/logv2/log.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
@@ -256,9 +257,9 @@ TEST_F(WiredTigerKVEngineTest, TestOplogTruncation) {
wiredTigerGlobalOptions.checkpointDelaySecs = 1;
// To diagnose any intermittent failures, maximize logging from WiredTigerKVEngine and friends.
- const auto kStorage = logger::LogComponent::kStorage;
+ const auto kStorage = logv2::LogComponent::kStorage;
auto originalVerbosity = getMinimumLogSeverity(kStorage);
- setMinimumLoggedSeverity(kStorage, logger::LogSeverity::Debug(3));
+ setMinimumLoggedSeverity(kStorage, logv2::LogSeverity::Debug(3));
ON_BLOCK_EXIT([&]() { setMinimumLoggedSeverity(kStorage, originalVerbosity); });
// Simulate the callback that queries config.transactions for the oldest active transaction.
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index b02fd45ba4c..61aca5cf9fa 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -55,6 +55,7 @@
#include "mongo/stdx/future.h"
#include "mongo/unittest/barrier.h"
#include "mongo/unittest/death_test.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/fail_point.h"
@@ -3668,7 +3669,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoVerbosityInfo) {
});
// Set verbosity level of transaction components to info.
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Info());
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Info());
txnParticipant.unstashTransactionResources(opCtx(), "commitTransaction");
@@ -3686,7 +3687,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoVerbosityDebug) {
auto txnParticipant = TransactionParticipant::get(opCtx());
// Set verbosity level of transaction components to debug.
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Debug(1));
txnParticipant.unstashTransactionResources(opCtx(), "commitTransaction");
@@ -3708,7 +3709,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoVerbosityDebug) {
stopCapturingLogMessages();
// Reset verbosity level of transaction components.
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Info());
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Info());
// Test that the transaction is still logged.
ASSERT_EQUALS(1, countTextFormatLogLinesContaining("transaction parameters"));
diff --git a/src/mongo/dbtests/framework_options.cpp b/src/mongo/dbtests/framework_options.cpp
index 3429cebc564..7c9eeec52d4 100644
--- a/src/mongo/dbtests/framework_options.cpp
+++ b/src/mongo/dbtests/framework_options.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/logv2/log.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
#include "mongo/util/options_parser/startup_options.h"
@@ -91,7 +92,7 @@ Status storeTestFrameworkOptions(const moe::Environment& params,
}
if (params.count("debug") || params.count("verbose")) {
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logv2::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 d5a2541d81b..d1b02379752 100644
--- a/src/mongo/logger/log_component_settings_test.cpp
+++ b/src/mongo/logger/log_component_settings_test.cpp
@@ -31,6 +31,7 @@
#include "mongo/logger/log_component.h"
#include "mongo/logger/log_component_settings.h"
+#include "mongo/logger/log_test.h"
#include "mongo/logger/logger.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/stdx/thread.h"
diff --git a/src/mongo/logger/log_test.h b/src/mongo/logger/log_test.h
index 72c4a12b00f..3fd731a437c 100644
--- a/src/mongo/logger/log_test.h
+++ b/src/mongo/logger/log_test.h
@@ -49,8 +49,55 @@
#include "mongo/util/log_global_settings.h"
namespace mongo {
+
+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 logger {
+
// Used for testing logging framework only.
// TODO(schwerin): Have logger write to a different log from the global log, so that tests can
// redirect their global log output for examination.
diff --git a/src/mongo/logv2/log_component.cpp b/src/mongo/logv2/log_component.cpp
index 0d893cffcb9..6ec5285ff86 100644
--- a/src/mongo/logv2/log_component.cpp
+++ b/src/mongo/logv2/log_component.cpp
@@ -247,5 +247,9 @@ StringData LogComponent::getNameForLog() const {
MONGO_UNREACHABLE;
}
+std::ostream& operator<<(std::ostream& os, LogComponent component) {
+ return os << component.getNameForLog();
+}
+
} // namespace logv2
} // namespace mongo
diff --git a/src/mongo/logv2/log_component.h b/src/mongo/logv2/log_component.h
index 75786334bc5..a508e3dc084 100644
--- a/src/mongo/logv2/log_component.h
+++ b/src/mongo/logv2/log_component.h
@@ -119,5 +119,7 @@ private:
Value _value;
};
+std::ostream& operator<<(std::ostream& os, LogComponent component);
+
} // namespace logv2
} // namespace mongo
diff --git a/src/mongo/logv2/log_severity.h b/src/mongo/logv2/log_severity.h
index 1db0ef775e2..dd6f4d1429c 100644
--- a/src/mongo/logv2/log_severity.h
+++ b/src/mongo/logv2/log_severity.h
@@ -143,6 +143,8 @@ private:
int _severity;
};
+std::ostream& operator<<(std::ostream& os, LogSeverity severity);
+
LogSeverity LogSeverity::Severe() {
return LogSeverity(-4);
}
diff --git a/src/mongo/rpc/op_msg_test.cpp b/src/mongo/rpc/op_msg_test.cpp
index 8ad5723e6ce..074b6ae1c05 100644
--- a/src/mongo/rpc/op_msg_test.cpp
+++ b/src/mongo/rpc/op_msg_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/op_msg.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
@@ -161,15 +162,15 @@ public:
class OpMsgParser : public unittest::Test {
public:
void setUp() override {
- _original = getMinimumLogSeverity(logger::LogComponent::kNetwork);
- setMinimumLoggedSeverity(logger::LogComponent::kNetwork, logger::LogSeverity::Debug(1));
+ _original = getMinimumLogSeverity(logv2::LogComponent::kNetwork);
+ setMinimumLoggedSeverity(logv2::LogComponent::kNetwork, logv2::LogSeverity::Debug(1));
}
void tearDown() override {
- setMinimumLoggedSeverity(logger::LogComponent::kNetwork, _original);
+ setMinimumLoggedSeverity(logv2::LogComponent::kNetwork, _original);
}
private:
- logger::LogSeverity _original = logger::LogSeverity::Debug(0);
+ logv2::LogSeverity _original = logv2::LogSeverity::Debug(0);
};
// Section bytes
diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp
index 295c22418e4..918344bedce 100644
--- a/src/mongo/s/mongos_options.cpp
+++ b/src/mongo/s/mongos_options.cpp
@@ -43,6 +43,7 @@
#include "mongo/config.h"
#include "mongo/db/server_options_base.h"
#include "mongo/db/server_options_server_helpers.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/version_mongos.h"
#include "mongo/util/log.h"
#include "mongo/util/net/socket_utils.h"
@@ -68,7 +69,8 @@ bool handlePreValidationMongosOptions(const moe::Environment& params,
return false;
}
if (params.count("test") && params["test"].as<bool>() == true) {
- setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Debug(5));
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, ::mongo::logv2::LogSeverity::Debug(5));
return false;
}
diff --git a/src/mongo/s/transaction_router_test.cpp b/src/mongo/s/transaction_router_test.cpp
index 2c97927e81b..b507662caeb 100644
--- a/src/mongo/s/transaction_router_test.cpp
+++ b/src/mongo/s/transaction_router_test.cpp
@@ -48,6 +48,7 @@
#include "mongo/s/sharding_router_test_fixture.h"
#include "mongo/s/transaction_router.h"
#include "mongo/unittest/death_test.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/fail_point.h"
@@ -3171,14 +3172,14 @@ TEST_F(TransactionRouterMetricsTest, OnlyLogSlowTransactionsOnce) {
TEST_F(TransactionRouterMetricsTest, NoTransactionsLoggedAtDefaultTransactionLogLevel) {
// Set verbosity level of transaction components to the default, i.e. debug level 0.
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Log());
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Log());
beginTxnWithDefaultTxnNumber();
runSingleShardCommit();
assertDidNotPrintSlowLogLine();
}
TEST_F(TransactionRouterMetricsTest, AllTransactionsLoggedAtTransactionLogLevelOne) {
- setMinimumLoggedSeverity(logger::LogComponent::kTransaction, logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(logv2::LogComponent::kTransaction, logv2::LogSeverity::Debug(1));
beginTxnWithDefaultTxnNumber();
runSingleShardCommit();
assertPrintedExactlyOneSlowLogLine();
diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp
index ee89ed985d4..eda52f5a155 100644
--- a/src/mongo/shell/shell_options.cpp
+++ b/src/mongo/shell/shell_options.cpp
@@ -112,7 +112,8 @@ Status storeMongoShellOptions(const moe::Environment& params,
}
if (params.count("verbose")) {
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, logv2::LogSeverity::Debug(1));
}
// `objcheck` option is part of `serverGlobalParams` to avoid making common parts depend upon
diff --git a/src/mongo/tools/mongobridge_options.cpp b/src/mongo/tools/mongobridge_options.cpp
index af1aee5fba6..6b29b3db7e8 100644
--- a/src/mongo/tools/mongobridge_options.cpp
+++ b/src/mongo/tools/mongobridge_options.cpp
@@ -35,8 +35,8 @@
#include <iostream>
#include "mongo/base/status.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
-#include "mongo/util/log.h"
#include "mongo/util/options_parser/startup_options.h"
namespace mongo {
@@ -81,7 +81,9 @@ Status storeMongoBridgeOptions(const moe::Environment& params,
return {ErrorCodes::BadValue,
"The string for the --verbose option cannot contain characters other than 'v'"};
}
- setMinimumLoggedSeverity(logger::LogSeverity::Debug(verbosity.length()));
+
+ logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, logv2::LogSeverity::Debug(verbosity.length()));
}
return Status::OK();
diff --git a/src/mongo/unittest/log_test.h b/src/mongo/unittest/log_test.h
new file mode 100644
index 00000000000..9f48830d958
--- /dev/null
+++ b/src/mongo/unittest/log_test.h
@@ -0,0 +1,66 @@
+/**
+ * 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,
+ * 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/logv2/log_component.h"
+#include "mongo/logv2/log_component_settings.h"
+#include "mongo/logv2/log_manager.h"
+#include "mongo/logv2/log_severity.h"
+
+namespace mongo {
+
+inline logv2::LogSeverity getMinimumLogSeverity() {
+ return logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(
+ mongo::logv2::LogComponent::kDefault);
+}
+
+inline logv2::LogSeverity getMinimumLogSeverity(logv2::LogComponent component) {
+ return logv2::LogManager::global().getGlobalSettings().getMinimumLogSeverity(component);
+}
+
+inline void setMinimumLoggedSeverity(logv2::LogSeverity severity) {
+ return logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(
+ mongo::logv2::LogComponent::kDefault, severity);
+}
+
+inline void setMinimumLoggedSeverity(logv2::LogComponent component, logv2::LogSeverity severity) {
+ return logv2::LogManager::global().getGlobalSettings().setMinimumLoggedSeverity(component,
+ severity);
+}
+
+inline void clearMinimumLoggedSeverity(logv2::LogComponent component) {
+ return logv2::LogManager::global().getGlobalSettings().clearMinimumLoggedSeverity(component);
+}
+
+inline bool hasMinimumLogSeverity(logv2::LogComponent component) {
+ return logv2::LogManager::global().getGlobalSettings().hasMinimumLogSeverity(component);
+}
+
+} // namespace mongo
diff --git a/src/mongo/unittest/unittest_main.cpp b/src/mongo/unittest/unittest_main.cpp
index f7bcd647c1a..3ddb44f977d 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/logv2/log_domain_global.h"
#include "mongo/logv2/log_manager.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/unittest/unittest_options_gen.h"
#include "mongo/util/log_global_settings.h"
@@ -94,7 +95,7 @@ int main(int argc, char** argv, char** envp) {
std::cerr << options.helpString();
return EXIT_FAILURE;
}
- mongo::setMinimumLoggedSeverity(::mongo::logger::LogSeverity::Debug(verbose.length()));
+ mongo::setMinimumLoggedSeverity(::mongo::logv2::LogSeverity::Debug(verbose.length()));
if (list) {
auto suiteNames = ::mongo::unittest::getAllSuiteNames();
diff --git a/src/mongo/util/log_global_settings.h b/src/mongo/util/log_global_settings.h
index ef0a1c022dd..ef409271d64 100644
--- a/src/mongo/util/log_global_settings.h
+++ b/src/mongo/util/log_global_settings.h
@@ -56,48 +56,4 @@ inline bool shouldLog(logger::LogComponent logComponent1, logger::LogSeverity se
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/log_with_sampling.h b/src/mongo/util/log_with_sampling.h
index 8a17ccd7dcd..71c5836fc44 100644
--- a/src/mongo/util/log_with_sampling.h
+++ b/src/mongo/util/log_with_sampling.h
@@ -34,6 +34,7 @@
#include "mongo/logger/log_component.h"
#include "mongo/logger/logger.h"
#include "mongo/logv2/log_component.h"
+#include "mongo/util/log_global_settings.h"
namespace mongo {
diff --git a/src/mongo/util/log_with_sampling_test.cpp b/src/mongo/util/log_with_sampling_test.cpp
index b47d37f87a4..069badc3004 100644
--- a/src/mongo/util/log_with_sampling_test.cpp
+++ b/src/mongo/util/log_with_sampling_test.cpp
@@ -32,7 +32,8 @@
#include "mongo/platform/basic.h"
#include "mongo/db/service_context_test_fixture.h"
-#include "mongo/util/log_global_settings.h"
+#include "mongo/logv2/log.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/util/log_with_sampling.h"
namespace mongo {
@@ -57,14 +58,11 @@ TEST(LogWithSamplingTest, ShouldLogCorrectlyWhenSampleRateIsSet) {
const auto slowOpDurationMS = Milliseconds(11);
// Set verbosity level of operation component to info so that it doesn't log due to the log
// level.
- setMinimumLoggedSeverity(MONGO_LOG_DEFAULT_COMPONENT, logger::LogSeverity::Info());
+ setMinimumLoggedSeverity(MongoLogV2DefaultComponent_component, logv2::LogSeverity::Info());
bool shouldLogSlowOp, shouldSample;
- std::tie(shouldLogSlowOp, shouldSample) =
- shouldLogSlowOpWithSampling(opCtx.get(),
- logComponentV1toV2(MONGO_LOG_DEFAULT_COMPONENT),
- slowOpDurationMS,
- slowOpThresholdMS);
+ std::tie(shouldLogSlowOp, shouldSample) = shouldLogSlowOpWithSampling(
+ opCtx.get(), MongoLogV2DefaultComponent_component, slowOpDurationMS, slowOpThresholdMS);
// Verify that shouldLogSlowOp is true when the sampleRate is 1.
ASSERT_TRUE(shouldLogSlowOp);
@@ -75,11 +73,8 @@ TEST(LogWithSamplingTest, ShouldLogCorrectlyWhenSampleRateIsSet) {
// Set sample rate to never profile a slow operation.
serverGlobalParams.sampleRate = 0;
- std::tie(shouldLogSlowOp, shouldSample) =
- shouldLogSlowOpWithSampling(opCtx.get(),
- logComponentV1toV2(MONGO_LOG_DEFAULT_COMPONENT),
- slowOpDurationMS,
- slowOpThresholdMS);
+ std::tie(shouldLogSlowOp, shouldSample) = shouldLogSlowOpWithSampling(
+ opCtx.get(), MongoLogV2DefaultComponent_component, slowOpDurationMS, slowOpThresholdMS);
// Verify that shouldLogSlowOp is false when the sampleRate is 0.
ASSERT_FALSE(shouldLogSlowOp);
@@ -105,14 +100,11 @@ TEST(LogWithSamplingTest, ShouldAlwaysLogsWithVerbosityLevelDebug) {
// Set the op duration to be greater than slowMS so that the op is considered slow.
const auto slowOpDurationMS = Milliseconds(11);
// Set verbosity level of operation component to debug so that it should always log.
- setMinimumLoggedSeverity(MONGO_LOG_DEFAULT_COMPONENT, logger::LogSeverity::Debug(1));
+ setMinimumLoggedSeverity(MongoLogV2DefaultComponent_component, logv2::LogSeverity::Debug(1));
bool shouldLogSlowOp, shouldSample;
- std::tie(shouldLogSlowOp, shouldSample) =
- shouldLogSlowOpWithSampling(opCtx.get(),
- logComponentV1toV2(MONGO_LOG_DEFAULT_COMPONENT),
- slowOpDurationMS,
- slowOpThresholdMS);
+ std::tie(shouldLogSlowOp, shouldSample) = shouldLogSlowOpWithSampling(
+ opCtx.get(), MongoLogV2DefaultComponent_component, slowOpDurationMS, slowOpThresholdMS);
// Verify that shouldLogSlowOp is true when the op is slow.
ASSERT_TRUE(shouldLogSlowOp);
@@ -123,11 +115,8 @@ TEST(LogWithSamplingTest, ShouldAlwaysLogsWithVerbosityLevelDebug) {
// Set sample rate to never profile a slow operation.
serverGlobalParams.sampleRate = 0;
- std::tie(shouldLogSlowOp, shouldSample) =
- shouldLogSlowOpWithSampling(opCtx.get(),
- logComponentV1toV2(MONGO_LOG_DEFAULT_COMPONENT),
- slowOpDurationMS,
- slowOpThresholdMS);
+ std::tie(shouldLogSlowOp, shouldSample) = shouldLogSlowOpWithSampling(
+ opCtx.get(), MongoLogV2DefaultComponent_component, slowOpDurationMS, slowOpThresholdMS);
// Verify that we should still log even when the sampleRate is 0.
ASSERT_TRUE(shouldLogSlowOp);
@@ -154,14 +143,11 @@ TEST(LogWithSamplingTest, ShouldNotLogFastOp) {
const auto fastOpDurationMS = Milliseconds(9);
// Set verbosity level of operation component to info so that it doesn't log due to the log
// level.
- setMinimumLoggedSeverity(MONGO_LOG_DEFAULT_COMPONENT, logger::LogSeverity::Info());
+ setMinimumLoggedSeverity(MongoLogV2DefaultComponent_component, logv2::LogSeverity::Info());
bool shouldLogSlowOp, shouldSample;
- std::tie(shouldLogSlowOp, shouldSample) =
- shouldLogSlowOpWithSampling(opCtx.get(),
- logComponentV1toV2(MONGO_LOG_DEFAULT_COMPONENT),
- fastOpDurationMS,
- slowOpThresholdMS);
+ std::tie(shouldLogSlowOp, shouldSample) = shouldLogSlowOpWithSampling(
+ opCtx.get(), MongoLogV2DefaultComponent_component, fastOpDurationMS, slowOpThresholdMS);
// Verify that shouldLogSlowOp is false when the op is fast.
ASSERT_FALSE(shouldLogSlowOp);
@@ -172,11 +158,8 @@ TEST(LogWithSamplingTest, ShouldNotLogFastOp) {
// Set sample rate to never profile a slow operation.
serverGlobalParams.sampleRate = 0;
- std::tie(shouldLogSlowOp, shouldSample) =
- shouldLogSlowOpWithSampling(opCtx.get(),
- logComponentV1toV2(MONGO_LOG_DEFAULT_COMPONENT),
- fastOpDurationMS,
- slowOpThresholdMS);
+ std::tie(shouldLogSlowOp, shouldSample) = shouldLogSlowOpWithSampling(
+ opCtx.get(), MongoLogV2DefaultComponent_component, fastOpDurationMS, slowOpThresholdMS);
// Verify that we should still not log when the sampleRate is 0.
ASSERT_FALSE(shouldLogSlowOp);