Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-52604

Log from anywhere (normalize MONGO_LOGV2_DEFAULT_COMPONENT)

    • 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.

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: