One of the most common mistakes observed during the code reviews for updating the sharding log lines based on the LOGV2 style guide (see SERVER-46799) was omitting a trailing comma to separate the format string from the message string, or to separate the message string from the first attribute name. There were 30 instances of this mistake made across the 10 individuals (myself included) who worked on those changes.
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 960d189008..04a7937b2d 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -651,7 +651,7 @@ ExitCode runMongosServer(ServiceContext* serviceContext) { if (!status.isOK()) { LOGV2_ERROR(22858, "Error initializing authorization data: {error}", - "Error initializing authorization data" + "Error initializing authorization data", "error"_attr = status); return EXIT_SHARDING_ERROR; }
This likely occurred due to the way in which engineers went about copy-pasting from the format string to create a sensible message string. It'd be great if the LOGV2 macros could protect against this, although perhaps unnecessary if we aren't going to require format strings in addition to message strings for new log messages. My idea for an approach would be to have the format and message strings be distinct nominal types and to have user-defined suffixes for creating the appropriate type. The compiler would error if two string literals with different ud-suffixes were attempted to be concatenated.
- depends on
-
SERVER-81602 Remove support for formatMsg from LOGV2
- Closed
- is related to
-
SERVER-46799 Update sharding log lines to adhere to LOGV2 style guide
- Closed