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

logv2 improve field padding

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.7.0
    • Affects Version/s: None
    • Component/s: Logging
    • Labels:
      None
    • Fully Compatible
    • Service Arch 2020-04-06, Service arch 2020-04-20, Service arch 2020-05-04

      The formatting code that pads the logv2 fields is currently very tricky and I've run into difficulty understanding extensions to it already in a couple code reviews.

      Easy to fix.

      Currently: 

           static const auto& fmtStrBody =
              *new auto(fmt::compile<StringData,  // severity start
                                     StringData,
                                     StringData,
                                     int,
                                     StringData,  // component start
                                     StringData,
                                     StringData,
                                     int,
                                     StringData,  // id start
                                     StringData,
                                     StringData,
                                     int,
                                     StringData,  // context start
                                     StringData,
                                     StringData>  // message start
                        (R"("}},)"                // close timestamp
                         R"("{}":"{}"{: <{}})"    // severity with padding for the comma
                         R"("{}":"{}"{: <{}})"    // component with padding for the comma
                         R"("{}":{}{: <{}})"      // id with padding for the comma
                         R"("{}":"{}",)"          // context
                         R"("{}":")"              // message
                         ));
          fmt::format_int idString(id);
          compiled_format_to(
              buffer,
              fmtStrBody,
              // severity, left align the comma and add padding to create fixed column width
              constants::kSeverityFieldName,
              severityString,
              ","_sd,
              3 - severityString.size(),
              // component, left align the comma and add padding to create fixed column width
              constants::kComponentFieldName,
              componentString,
              ","_sd,
              9 - componentString.size(),
              // id
              constants::kIdFieldName,
              StringData(idString.data(), idString.size()),
              ","_sd,
              8 - idString.size(),
              // context
              constants::kContextFieldName,
              context,
              // message
              constants::kMessageFieldName);
      
      

       

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

              Created:
              Updated:
              Resolved: