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