-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Internal Code
-
Fully Compatible
-
Service Arch 2022-05-16
The #define MONGO_LOGV2_DEFAULT_COMPONENT definition is well-known to be a C++ design problem. It has to appear before including headers, etc.
This inverted dependency of a header upon its includer affects considerations of precompiled headers(PM-2150) or C++ modules(PM-2149).
All we have to do is move that definition down below the include files, like any other local macro, and it's much more conventional C++.
If you want to define it in a header and do some LOGV2 logging from inline functions, that's ok, just #undef it at the bottom. There is no ODR problem if an inline function has LOGV2 statements, as long as it always contains the same body, which it will. Nothing bad happens.
log.h can switch from asserting that the macro IS defined to asserting that the macro is NOT defined when log.h is included.
#define MONGO_LOGV2_DEFAULT_COMPONENT x #include "mongo/logv2/log.h" ...
to
#include "mongo/logv2/log.h" ... #define MONGO_LOGV2_DEFAULT_COMPONENT x
Then we don't have a #define that must appear before header includes.
A side-effect of this is change is that shouldLog's component argument becomes mandatory. This is easy to do and only affects 5 or 6 calls.
- depends on
-
SERVER-54596 1-arg shouldLog violates One Definition Rule
- Closed
- related to
-
SERVER-80847 reinforce MONGO_LOGV2_DEFAULT_COMPONENT placement rule
- Closed
- split to
-
SERVER-66202 MONGO_LOGV2_DEFAULT_COMPONENT conventions lint check
- Closed
-
SERVER-66203 Sweep: move MONGO_LOGV2_DEFAULT_COMPONENT definition below includes
- Closed