summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2022-05-04 22:21:50 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-04 23:17:39 +0000
commit1634edc01f2fc41d1a4e61f3802c5cec90e0e793 (patch)
treed024d99b723c5055ff6fe527ffa706ac2a8912b8 /src/mongo
parent25c0fbade9ec93a3c5458fc5c7d2481adad064c7 (diff)
downloadmongo-1634edc01f2fc41d1a4e61f3802c5cec90e0e793.tar.gz
SERVER-52604 normalize log.h inclusion semantics
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/internal_transactions_test_command_d.cpp2
-rw-r--r--src/mongo/db/commands/killoperations_cmd.cpp7
-rw-r--r--src/mongo/db/commands/killoperations_common.h11
-rw-r--r--src/mongo/db/process_health/config_server_health_observer.cpp2
-rw-r--r--src/mongo/db/process_health/fault_facet_mock.h6
-rw-r--r--src/mongo/db/process_health/fault_manager_test_suite.h10
-rw-r--r--src/mongo/db/process_health/health_observer_mock.h5
-rw-r--r--src/mongo/db/process_health/health_observer_test.cpp3
-rw-r--r--src/mongo/db/s/balancer/migration_test_fixture.h4
-rw-r--r--src/mongo/db/s/sharding_data_transform_cumulative_metrics_test.cpp5
-rw-r--r--src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp5
-rw-r--r--src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h8
-rw-r--r--src/mongo/db/storage/kv/storage_engine_test.cpp3
-rw-r--r--src/mongo/db/storage/storage_engine_test_fixture.h6
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp2
-rw-r--r--src/mongo/logv2/log.h211
-rw-r--r--src/mongo/s/commands/cluster_killoperations_cmd.cpp5
-rw-r--r--src/mongo/s/commands/internal_transactions_test_command.h5
18 files changed, 143 insertions, 157 deletions
diff --git a/src/mongo/db/commands/internal_transactions_test_command_d.cpp b/src/mongo/db/commands/internal_transactions_test_command_d.cpp
index 4a8570cc87f..fa010df9b25 100644
--- a/src/mongo/db/commands/internal_transactions_test_command_d.cpp
+++ b/src/mongo/db/commands/internal_transactions_test_command_d.cpp
@@ -27,8 +27,6 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
-
#include "mongo/db/cluster_transaction_api.h"
#include "mongo/db/transaction_participant_resource_yielder.h"
#include "mongo/s/commands/internal_transactions_test_command.h"
diff --git a/src/mongo/db/commands/killoperations_cmd.cpp b/src/mongo/db/commands/killoperations_cmd.cpp
index 05a2d703342..1709b438fb0 100644
--- a/src/mongo/db/commands/killoperations_cmd.cpp
+++ b/src/mongo/db/commands/killoperations_cmd.cpp
@@ -27,10 +27,11 @@
* it in the license file.
*/
-#include "mongo/platform/basic.h"
-
#include "mongo/db/commands/killoperations_common.h"
#include "mongo/db/cursor_manager.h"
+#include "mongo/logv2/log.h"
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
namespace mongo {
@@ -50,6 +51,6 @@ public:
}
}
}
-} KillOperationsCmd;
+} killOperationsCmd;
} // namespace mongo
diff --git a/src/mongo/db/commands/killoperations_common.h b/src/mongo/db/commands/killoperations_common.h
index b9dd9eb79a9..ca968da0af5 100644
--- a/src/mongo/db/commands/killoperations_common.h
+++ b/src/mongo/db/commands/killoperations_common.h
@@ -27,12 +27,6 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/commands/kill_operations_gen.h"
-
#include <fmt/format.h>
#include "mongo/base/init.h"
@@ -41,12 +35,15 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
+#include "mongo/db/commands/kill_operations_gen.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/operation_killer.h"
#include "mongo/db/service_context.h"
#include "mongo/logv2/log.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
namespace mongo {
template <typename Derived>
@@ -119,3 +116,5 @@ private:
};
} // namespace mongo
+
+#undef MONGO_LOGV2_DEFAULT_COMPONENT
diff --git a/src/mongo/db/process_health/config_server_health_observer.cpp b/src/mongo/db/process_health/config_server_health_observer.cpp
index 37f1a8644d4..1ffb7989b70 100644
--- a/src/mongo/db/process_health/config_server_health_observer.cpp
+++ b/src/mongo/db/process_health/config_server_health_observer.cpp
@@ -26,7 +26,7 @@
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kProcessHealth;
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kProcessHealth
#include <random>
diff --git a/src/mongo/db/process_health/fault_facet_mock.h b/src/mongo/db/process_health/fault_facet_mock.h
index b1f1589d320..e6c9ee5325b 100644
--- a/src/mongo/db/process_health/fault_facet_mock.h
+++ b/src/mongo/db/process_health/fault_facet_mock.h
@@ -28,8 +28,6 @@
*/
#pragma once
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
-
#include <functional>
#include "mongo/db/process_health/fault_facet.h"
@@ -39,6 +37,8 @@
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/timer.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
+
namespace mongo {
namespace process_health {
@@ -89,3 +89,5 @@ private:
} // namespace process_health
} // namespace mongo
+
+#undef MONGO_LOGV2_DEFAULT_COMPONENT
diff --git a/src/mongo/db/process_health/fault_manager_test_suite.h b/src/mongo/db/process_health/fault_manager_test_suite.h
index 67e9f2d506c..f49cd682256 100644
--- a/src/mongo/db/process_health/fault_manager_test_suite.h
+++ b/src/mongo/db/process_health/fault_manager_test_suite.h
@@ -30,18 +30,20 @@
#include <memory>
-#include "mongo/db/process_health/fault_manager.h"
-
#include "mongo/db/concurrency/locker_noop_client_observer.h"
+#include "mongo/db/process_health/fault_manager.h"
#include "mongo/db/process_health/health_observer_mock.h"
#include "mongo/db/process_health/health_observer_registration.h"
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
#include "mongo/idl/server_parameter_test_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/concurrency/thread_pool.h"
#include "mongo/util/tick_source_mock.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
+
namespace mongo {
using executor::TaskExecutor;
@@ -51,7 +53,7 @@ namespace process_health {
namespace test {
-static inline std::unique_ptr<FaultManagerConfig> getConfigWithDisabledPeriodicChecks() {
+inline std::unique_ptr<FaultManagerConfig> getConfigWithDisabledPeriodicChecks() {
auto config = std::make_unique<FaultManagerConfig>();
config->disablePeriodicChecksForTests();
return config;
@@ -291,3 +293,5 @@ private:
} // namespace test
} // namespace process_health
} // namespace mongo
+
+#undef MONGO_LOGV2_DEFAULT_COMPONENT
diff --git a/src/mongo/db/process_health/health_observer_mock.h b/src/mongo/db/process_health/health_observer_mock.h
index 80051dc5eac..e7a500bdf8c 100644
--- a/src/mongo/db/process_health/health_observer_mock.h
+++ b/src/mongo/db/process_health/health_observer_mock.h
@@ -32,6 +32,9 @@
#include "mongo/db/process_health/fault_facet_mock.h"
#include "mongo/db/process_health/health_observer_base.h"
+#include "mongo/logv2/log.h"
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
namespace mongo {
namespace process_health {
@@ -101,3 +104,5 @@ private:
} // namespace process_health
} // namespace mongo
+
+#undef MONGO_LOGV2_DEFAULT_COMPONENT
diff --git a/src/mongo/db/process_health/health_observer_test.cpp b/src/mongo/db/process_health/health_observer_test.cpp
index f10d2683967..7cbbd52c154 100644
--- a/src/mongo/db/process_health/health_observer_test.cpp
+++ b/src/mongo/db/process_health/health_observer_test.cpp
@@ -33,9 +33,12 @@
#include "mongo/db/process_health/health_observer_mock.h"
#include "mongo/db/process_health/health_observer_registration.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/timer.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
+
namespace mongo {
namespace process_health {
diff --git a/src/mongo/db/s/balancer/migration_test_fixture.h b/src/mongo/db/s/balancer/migration_test_fixture.h
index 76d13c587d7..6ea36503330 100644
--- a/src/mongo/db/s/balancer/migration_test_fixture.h
+++ b/src/mongo/db/s/balancer/migration_test_fixture.h
@@ -27,10 +27,6 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
-
-#include "mongo/platform/basic.h"
-
#include <memory>
#include "mongo/client/remote_command_targeter_mock.h"
diff --git a/src/mongo/db/s/sharding_data_transform_cumulative_metrics_test.cpp b/src/mongo/db/s/sharding_data_transform_cumulative_metrics_test.cpp
index 703ca850915..2b769db1fe4 100644
--- a/src/mongo/db/s/sharding_data_transform_cumulative_metrics_test.cpp
+++ b/src/mongo/db/s/sharding_data_transform_cumulative_metrics_test.cpp
@@ -27,12 +27,11 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
-
#include "mongo/platform/basic.h"
#include "mongo/db/s/sharding_data_transform_cumulative_metrics.h"
#include "mongo/db/s/sharding_data_transform_metrics_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/stdx/thread.h"
#include "mongo/stdx/unordered_map.h"
@@ -40,6 +39,8 @@
#include "mongo/util/future.h"
#include "mongo/util/static_immortal.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
+
namespace mongo {
namespace {
diff --git a/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp b/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp
index 80123d08041..6d536768955 100644
--- a/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp
+++ b/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp
@@ -27,16 +27,17 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
-
#include "mongo/platform/basic.h"
#include "mongo/db/s/sharding_data_transform_cumulative_metrics.h"
#include "mongo/db/s/sharding_data_transform_instance_metrics.h"
#include "mongo/db/s/sharding_data_transform_metrics_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/duration.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
+
namespace mongo {
namespace {
diff --git a/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h b/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h
index 9cfecd7bcfb..5db7589330f 100644
--- a/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h
+++ b/src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h
@@ -27,10 +27,6 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
-
-#include "mongo/platform/basic.h"
-
#include "mongo/db/s/sharding_data_transform_cumulative_metrics.h"
#include "mongo/db/s/sharding_data_transform_instance_metrics.h"
#include "mongo/logv2/log.h"
@@ -42,6 +38,8 @@
#include "mongo/util/future.h"
#include "mongo/util/static_immortal.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
+
namespace mongo {
class ObserverMock : public ShardingDataTransformMetricsObserverInterface {
@@ -234,3 +232,5 @@ protected:
};
} // namespace mongo
+
+#undef MONGO_LOGV2_DEFAULT_COMPONENT
diff --git a/src/mongo/db/storage/kv/storage_engine_test.cpp b/src/mongo/db/storage/kv/storage_engine_test.cpp
index 828b1ad3f5a..85917569697 100644
--- a/src/mongo/db/storage/kv/storage_engine_test.cpp
+++ b/src/mongo/db/storage/kv/storage_engine_test.cpp
@@ -49,11 +49,14 @@
#include "mongo/db/storage/storage_engine_impl.h"
#include "mongo/db/storage/storage_engine_test_fixture.h"
#include "mongo/db/storage/storage_repair_observer.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/barrier.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/future.h"
#include "mongo/util/periodic_runner_factory.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
+
namespace mongo {
namespace {
diff --git a/src/mongo/db/storage/storage_engine_test_fixture.h b/src/mongo/db/storage/storage_engine_test_fixture.h
index 49904d0160e..96d3c7d0af8 100644
--- a/src/mongo/db/storage/storage_engine_test_fixture.h
+++ b/src/mongo/db/storage/storage_engine_test_fixture.h
@@ -29,8 +29,6 @@
#pragma once
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
-
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/catalog/collection_impl.h"
#include "mongo/db/catalog_raii.h"
@@ -44,6 +42,8 @@
#include "mongo/db/storage/storage_repair_observer.h"
#include "mongo/logv2/log.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
+
namespace mongo {
class StorageEngineTest : public ServiceContextMongoDTest {
@@ -218,3 +218,5 @@ public:
};
} // namespace mongo
+
+#undef MONGO_LOGV2_DEFAULT_COMPONENT
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
index a2217640963..8ff08bb1605 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
@@ -721,7 +721,7 @@ int mdb_handle_error(WT_EVENT_HANDLER* handler,
int mdb_handle_message(WT_EVENT_HANDLER* handler, WT_SESSION* session, const char* message) {
logv2::DynamicAttributes attr;
logv2::LogSeverity severity = ::mongo::logv2::LogSeverity::Log();
- logv2::LogOptions options = ::mongo::logv2::LogOptions{MongoLogV2DefaultComponent_component};
+ logv2::LogOptions options = ::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT};
try {
try {
diff --git a/src/mongo/logv2/log.h b/src/mongo/logv2/log.h
index 27e8f9f52fe..d887e6ea351 100644
--- a/src/mongo/logv2/log.h
+++ b/src/mongo/logv2/log.h
@@ -27,22 +27,7 @@
* it in the license file.
*/
-// #pragma once is not used in this header.
-// This header attempts to enforce the rule that no logging should be done in
-// an inline function defined in a header.
-// To enforce this "no logging in header" rule, we use #include guards with a validating #else
-// clause.
-// Also, this header relies on a preprocessor macro to determine the default component for the
-// unconditional logging functions severe(), error(), warning() and log(). Disallowing multiple
-// inclusion of log.h will ensure that the default component will be set correctly.
-
-#if defined(MONGO_UTIL_LOGV2_H_)
-#error \
- "mongo/logv2/log.h cannot be included multiple times. " \
- "This may occur when log.h is included in a header. " \
- "Please check your #include's."
-#else // MONGO_UTIL_LOGV2_H_
-#define MONGO_UTIL_LOGV2_H_
+#pragma once
#include "mongo/base/status.h"
#include "mongo/bson/util/builder.h"
@@ -56,26 +41,16 @@
#include "mongo/logv2/redaction.h"
#include "mongo/util/errno_util.h"
-namespace {
-#if defined(MONGO_LOGV2_DEFAULT_COMPONENT)
-// Provide log component in global scope so that MONGO_LOG will always have a valid component.
-// Global log component will be kDefault unless overridden by MONGO_LOGV2_DEFAULT_COMPONENT.
-const mongo::logv2::LogComponent MongoLogV2DefaultComponent_component =
- MONGO_LOGV2_DEFAULT_COMPONENT;
-#else
-#error \
- "mongo/logv2/log.h requires MONGO_LOGV2_DEFAULT_COMPONENT to be defined. " \
- "Please see https://github.com/mongodb/mongo/blob/master/docs/logging.md "
-#endif // MONGO_LOGV2_DEFAULT_COMPONENT
-} // namespace
-
// The logging macros below are documented in detail under docs/logging.md
-namespace mongo {
-// Internal helper to be able to create LogOptions with two arguments from other macros
-#define MAKE_OPTIONS_ARG2(ARG0, ARG1) \
- ::mongo::logv2::LogOptions { \
- ARG0, ARG1 \
- }
+//
+// They all (except LOGV2_IMPL) require a `MONGO_LOGV2_DEFAULT_COMPONENT` macro.
+// This configuration macro must expand at their point of use to a
+// `LogComponent` expression. For example:
+//
+// #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
+//
+// LOGV2(1234500, "Something interesting happened");
+//
// Internal helper to perform the logging where it requires the MESSAGE to be a compile time string.
#define LOGV2_IMPL(ID, SEVERITY, OPTIONS, FMTSTR_MESSAGE, ...) \
@@ -98,11 +73,11 @@ namespace mongo {
* DYNAMIC_ATTRIBUTES single argument DynamicAttributes object
* no attributes may be passed with "name"_attr=value when this is used
*/
-#define LOGV2(ID, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Log(), \
- ::mongo::logv2::LogOptions{MongoLogV2DefaultComponent_component}, \
- FMTSTR_MESSAGE, \
+#define LOGV2(ID, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL(ID, \
+ ::mongo::logv2::LogSeverity::Log(), \
+ ::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT}, \
+ FMTSTR_MESSAGE, \
##__VA_ARGS__)
/**
@@ -113,24 +88,24 @@ namespace mongo {
*
* See LOGV2() for documentation of the other parameters
*/
-#define LOGV2_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Log(), \
- ::mongo::logv2::LogOptions::ensureValidComponent( \
- OPTIONS, MongoLogV2DefaultComponent_component), \
- FMTSTR_MESSAGE, \
- ##__VA_ARGS__)
+#define LOGV2_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL( \
+ ID, \
+ ::mongo::logv2::LogSeverity::Log(), \
+ ::mongo::logv2::LogOptions::ensureValidComponent(OPTIONS, MONGO_LOGV2_DEFAULT_COMPONENT), \
+ FMTSTR_MESSAGE, \
+ ##__VA_ARGS__)
/**
* Log with info severity.
*
* See LOGV2() for documentation of the parameters
*/
-#define LOGV2_INFO(ID, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Info(), \
- ::mongo::logv2::LogOptions{MongoLogV2DefaultComponent_component}, \
- FMTSTR_MESSAGE, \
+#define LOGV2_INFO(ID, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL(ID, \
+ ::mongo::logv2::LogSeverity::Info(), \
+ ::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT}, \
+ FMTSTR_MESSAGE, \
##__VA_ARGS__)
/**
@@ -138,24 +113,24 @@ namespace mongo {
*
* See LOGV2_OPTIONS() for documentation of the parameters
*/
-#define LOGV2_INFO_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Info(), \
- ::mongo::logv2::LogOptions::ensureValidComponent( \
- OPTIONS, MongoLogV2DefaultComponent_component), \
- FMTSTR_MESSAGE, \
- ##__VA_ARGS__)
+#define LOGV2_INFO_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL( \
+ ID, \
+ ::mongo::logv2::LogSeverity::Info(), \
+ ::mongo::logv2::LogOptions::ensureValidComponent(OPTIONS, MONGO_LOGV2_DEFAULT_COMPONENT), \
+ FMTSTR_MESSAGE, \
+ ##__VA_ARGS__)
/**
* Log with warning severity.
*
* See LOGV2() for documentation of the parameters
*/
-#define LOGV2_WARNING(ID, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Warning(), \
- ::mongo::logv2::LogOptions{MongoLogV2DefaultComponent_component}, \
- FMTSTR_MESSAGE, \
+#define LOGV2_WARNING(ID, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL(ID, \
+ ::mongo::logv2::LogSeverity::Warning(), \
+ ::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT}, \
+ FMTSTR_MESSAGE, \
##__VA_ARGS__)
/**
@@ -163,24 +138,24 @@ namespace mongo {
*
* See LOGV2_OPTIONS() for documentation of the parameters
*/
-#define LOGV2_WARNING_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Warning(), \
- ::mongo::logv2::LogOptions::ensureValidComponent( \
- OPTIONS, MongoLogV2DefaultComponent_component), \
- FMTSTR_MESSAGE, \
- ##__VA_ARGS__)
+#define LOGV2_WARNING_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL( \
+ ID, \
+ ::mongo::logv2::LogSeverity::Warning(), \
+ ::mongo::logv2::LogOptions::ensureValidComponent(OPTIONS, MONGO_LOGV2_DEFAULT_COMPONENT), \
+ FMTSTR_MESSAGE, \
+ ##__VA_ARGS__)
/**
* Log with error severity.
*
* See LOGV2() for documentation of the parameters
*/
-#define LOGV2_ERROR(ID, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Error(), \
- ::mongo::logv2::LogOptions{MongoLogV2DefaultComponent_component}, \
- FMTSTR_MESSAGE, \
+#define LOGV2_ERROR(ID, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL(ID, \
+ ::mongo::logv2::LogSeverity::Error(), \
+ ::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT}, \
+ FMTSTR_MESSAGE, \
##__VA_ARGS__)
/**
@@ -188,27 +163,27 @@ namespace mongo {
*
* See LOGV2_OPTIONS() for documentation of the parameters
*/
-#define LOGV2_ERROR_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Error(), \
- ::mongo::logv2::LogOptions::ensureValidComponent( \
- OPTIONS, MongoLogV2DefaultComponent_component), \
- FMTSTR_MESSAGE, \
- ##__VA_ARGS__)
+#define LOGV2_ERROR_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL( \
+ ID, \
+ ::mongo::logv2::LogSeverity::Error(), \
+ ::mongo::logv2::LogOptions::ensureValidComponent(OPTIONS, MONGO_LOGV2_DEFAULT_COMPONENT), \
+ FMTSTR_MESSAGE, \
+ ##__VA_ARGS__)
/**
* Log with fatal severity. fassertFailed(ID) will be performed after writing the log
*
* See LOGV2() for documentation of the parameters
*/
-#define LOGV2_FATAL(ID, FMTSTR_MESSAGE, ...) \
- do { \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Severe(), \
- ::mongo::logv2::LogOptions{MongoLogV2DefaultComponent_component}, \
- FMTSTR_MESSAGE, \
- ##__VA_ARGS__); \
- fassertFailed(ID); \
+#define LOGV2_FATAL(ID, FMTSTR_MESSAGE, ...) \
+ do { \
+ LOGV2_IMPL(ID, \
+ ::mongo::logv2::LogSeverity::Severe(), \
+ ::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT}, \
+ FMTSTR_MESSAGE, \
+ ##__VA_ARGS__); \
+ fassertFailed(ID); \
} while (false)
/**
@@ -216,15 +191,15 @@ namespace mongo {
*
* See LOGV2() for documentation of the parameters
*/
-#define LOGV2_FATAL_NOTRACE(ID, FMTSTR_MESSAGE, ...) \
- do { \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Severe(), \
- MAKE_OPTIONS_ARG2(MongoLogV2DefaultComponent_component, \
- ::mongo::logv2::FatalMode::kAssertNoTrace), \
- FMTSTR_MESSAGE, \
- ##__VA_ARGS__); \
- fassertFailedNoTrace(ID); \
+#define LOGV2_FATAL_NOTRACE(ID, FMTSTR_MESSAGE, ...) \
+ do { \
+ LOGV2_IMPL(ID, \
+ ::mongo::logv2::LogSeverity::Severe(), \
+ (::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT, \
+ ::mongo::logv2::FatalMode::kAssertNoTrace}), \
+ FMTSTR_MESSAGE, \
+ ##__VA_ARGS__); \
+ fassertFailedNoTrace(ID); \
} while (false)
/**
@@ -232,12 +207,12 @@ namespace mongo {
*
* See LOGV2() for documentation of the parameters
*/
-#define LOGV2_FATAL_CONTINUE(ID, FMTSTR_MESSAGE, ...) \
- LOGV2_IMPL(ID, \
- ::mongo::logv2::LogSeverity::Severe(), \
- MAKE_OPTIONS_ARG2(MongoLogV2DefaultComponent_component, \
- ::mongo::logv2::FatalMode::kContinue), \
- FMTSTR_MESSAGE, \
+#define LOGV2_FATAL_CONTINUE(ID, FMTSTR_MESSAGE, ...) \
+ LOGV2_IMPL(ID, \
+ ::mongo::logv2::LogSeverity::Severe(), \
+ (::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT, \
+ ::mongo::logv2::FatalMode::kContinue}), \
+ FMTSTR_MESSAGE, \
##__VA_ARGS__)
/**
@@ -250,7 +225,7 @@ namespace mongo {
#define LOGV2_FATAL_OPTIONS(ID, OPTIONS, FMTSTR_MESSAGE, ...) \
do { \
auto optionsMacroLocal_ = ::mongo::logv2::LogOptions::ensureValidComponent( \
- OPTIONS, MongoLogV2DefaultComponent_component); \
+ OPTIONS, MONGO_LOGV2_DEFAULT_COMPONENT); \
LOGV2_IMPL(ID, \
::mongo::logv2::LogSeverity::Severe(), \
optionsMacroLocal_, \
@@ -277,7 +252,7 @@ namespace mongo {
do { \
auto severityMacroLocal_ = ::mongo::logv2::LogSeverity::Debug(DLEVEL); \
auto optionsMacroLocal_ = ::mongo::logv2::LogOptions::ensureValidComponent( \
- OPTIONS, MongoLogV2DefaultComponent_component); \
+ OPTIONS, MONGO_LOGV2_DEFAULT_COMPONENT); \
if (::mongo::logv2::LogManager::global().getGlobalSettings().shouldLog( \
optionsMacroLocal_.component(), severityMacroLocal_)) { \
LOGV2_IMPL( \
@@ -292,17 +267,15 @@ namespace mongo {
*
* See LOGV2() for documentation of the other parameters
*/
-#define LOGV2_DEBUG(ID, DLEVEL, FMTSTR_MESSAGE, ...) \
- LOGV2_DEBUG_OPTIONS(ID, \
- DLEVEL, \
- ::mongo::logv2::LogOptions{MongoLogV2DefaultComponent_component}, \
- FMTSTR_MESSAGE, \
+#define LOGV2_DEBUG(ID, DLEVEL, FMTSTR_MESSAGE, ...) \
+ LOGV2_DEBUG_OPTIONS(ID, \
+ DLEVEL, \
+ ::mongo::logv2::LogOptions{MONGO_LOGV2_DEFAULT_COMPONENT}, \
+ FMTSTR_MESSAGE, \
##__VA_ARGS__)
-inline bool shouldLog(logv2::LogComponent logComponent, logv2::LogSeverity severity) {
- return logv2::LogManager::global().getGlobalSettings().shouldLog(logComponent, severity);
+namespace mongo::logv2 {
+inline bool shouldLog(LogComponent logComponent, LogSeverity severity) {
+ return LogManager::global().getGlobalSettings().shouldLog(logComponent, severity);
}
-
-} // namespace mongo
-
-#endif // MONGO_UTIL_LOGV2_H_
+} // namespace mongo::logv2
diff --git a/src/mongo/s/commands/cluster_killoperations_cmd.cpp b/src/mongo/s/commands/cluster_killoperations_cmd.cpp
index 0dfc1676438..4ca775e2235 100644
--- a/src/mongo/s/commands/cluster_killoperations_cmd.cpp
+++ b/src/mongo/s/commands/cluster_killoperations_cmd.cpp
@@ -30,10 +30,13 @@
#include "mongo/platform/basic.h"
#include "mongo/db/commands/killoperations_common.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_cursor_manager.h"
#include "mongo/stdx/unordered_set.h"
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
namespace mongo {
class ClusterKillOperationsCmd : public KillOperationsCmdBase<ClusterKillOperationsCmd> {
@@ -63,6 +66,6 @@ public:
LOGV2(
4664806, "_killOperations command killed cursors", "numKilled"_attr = numCursorsKilled);
}
-} ClusterKillOperationsCmd;
+} clusterKillOperationsCmd;
} // namespace mongo
diff --git a/src/mongo/s/commands/internal_transactions_test_command.h b/src/mongo/s/commands/internal_transactions_test_command.h
index c5bf8b61951..b6988100710 100644
--- a/src/mongo/s/commands/internal_transactions_test_command.h
+++ b/src/mongo/s/commands/internal_transactions_test_command.h
@@ -27,19 +27,15 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
-
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/internal_transactions_test_command_gen.h"
#include "mongo/db/query/find_command_gen.h"
#include "mongo/db/transaction_api.h"
-#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/stdx/future.h"
namespace mongo {
-namespace {
template <typename Impl>
class InternalTransactionsTestCommandBase : public TypedCommand<Impl> {
@@ -174,5 +170,4 @@ public:
}
};
-} // namespace
} // namespace mongo