Skip to content

Commit

Permalink
SERVER-52604 normalize log.h inclusion semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyDonahue authored and Evergreen Agent committed May 4, 2022
1 parent 25c0fba commit 1634edc
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 159 deletions.
7 changes: 5 additions & 2 deletions docs/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ The log system is made available with the following header:

#include "mongo/logv2/log.h"

To be able to include it a default log component needs to be defined in the cpp
file before including `log.h`:
The macro `MONGO_LOGV2_DEFAULT_COMPONENT` is expanded by all logging macros.
This configuration macro must expand at their point of use to a `LogComponent`
expression, which is implicitly attached to the emitted message. It is
conventionally defined near the top of a `.cpp` file before any logging macros
are invoked. Example:

#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions src/mongo/db/commands/killoperations_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -50,6 +51,6 @@ class KillOperationsCmd : public KillOperationsCmdBase<KillOperationsCmd> {
}
}
}
} KillOperationsCmd;
} killOperationsCmd;

} // namespace mongo
11 changes: 5 additions & 6 deletions src/mongo/db/commands/killoperations_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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>
Expand Down Expand Up @@ -119,3 +116,5 @@ class KillOperationsCmdBase : public TypedCommand<Derived> {
};

} // namespace mongo

#undef MONGO_LOGV2_DEFAULT_COMPONENT
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
6 changes: 4 additions & 2 deletions src/mongo/db/process_health/fault_facet_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {

Expand Down Expand Up @@ -89,3 +89,5 @@ class FaultFacetMock : public FaultFacet {

} // namespace process_health
} // namespace mongo

#undef MONGO_LOGV2_DEFAULT_COMPONENT
10 changes: 7 additions & 3 deletions src/mongo/db/process_health/fault_manager_test_suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -291,3 +293,5 @@ class FaultManagerTest : public unittest::Test {
} // namespace test
} // namespace process_health
} // namespace mongo

#undef MONGO_LOGV2_DEFAULT_COMPONENT
5 changes: 5 additions & 0 deletions src/mongo/db/process_health/health_observer_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -101,3 +104,5 @@ class HealthObserverMock : public HealthObserverBase {

} // namespace process_health
} // namespace mongo

#undef MONGO_LOGV2_DEFAULT_COMPONENT
3 changes: 3 additions & 0 deletions src/mongo/db/process_health/health_observer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/mongo/db/s/balancer/migration_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
* 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"
#include "mongo/unittest/unittest.h"
#include "mongo/util/future.h"
#include "mongo/util/static_immortal.h"

#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest

namespace mongo {
namespace {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
8 changes: 4 additions & 4 deletions src/mongo/db/s/sharding_data_transform_metrics_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -234,3 +232,5 @@ class ShardingDataTransformMetricsTestFixture : public unittest::Test {
};

} // namespace mongo

#undef MONGO_LOGV2_DEFAULT_COMPONENT
3 changes: 3 additions & 0 deletions src/mongo/db/storage/kv/storage_engine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
6 changes: 4 additions & 2 deletions src/mongo/db/storage/storage_engine_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -218,3 +218,5 @@ class StorageEngineRepairTest : public StorageEngineTest {
};

} // namespace mongo

#undef MONGO_LOGV2_DEFAULT_COMPONENT
2 changes: 1 addition & 1 deletion src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 1634edc

Please sign in to comment.