[SERVER-47220] logv2 improve field padding Created: 01/Apr/20  Updated: 29/Oct/23  Resolved: 21/Apr/20

Status: Closed
Project: Core Server
Component/s: Logging
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2020-04-06, Service arch 2020-04-20, Service arch 2020-05-04
Participants:

 Description   

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);

 



 Comments   
Comment by Githook User [ 01/May/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-47220 log json field padding

(cherry picked from commit 10ee8c156f747c55895067cb418827c57c59557b)
Branch: v4.4
https://github.com/mongodb/mongo/commit/5084c9fbef6ef7590aeeffae65c2ef99f709077f

Comment by Githook User [ 21/Apr/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-47220 log json field padding
Branch: master
https://github.com/mongodb/mongo/commit/10ee8c156f747c55895067cb418827c57c59557b

Comment by Billy Donahue [ 13/Apr/20 ]

CR https://mongodbcr.appspot.com/582790067/

Generated at Thu Feb 08 05:13:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.