Skip to content

Commit

Permalink
util/log: allow bool fields to be emitted as false in json format
Browse files Browse the repository at this point in the history
Previously with the json logging format, it was not possible to emit
boolean fields that were false. Even if the boolean field is marked as
'includeempty', it will be emitted as `field: true` in the event.
While always not including false boolean fields is more space efficient,
with certain fields it's helpful to have the field emitted in all
instances and explicitly state its 'false' value.

This patch makes it possible for `fieldName: false` to be emitted
in the json logging format when the field is marked as `includeempty`.

Epic: none
Part of: cockroachdb#108284

Release note: None
  • Loading branch information
xinhaoz committed Nov 3, 2023
1 parent 974b43d commit 7d1cde5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 30 deletions.
3 changes: 2 additions & 1 deletion pkg/util/log/eventpb/eventpbgen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ func (m *{{.GoType}}) AppendJSONFields(printComma bool, b redact.RedactableBytes
if m.{{.FieldName}} {
{{- end }}
if printComma { b = append(b, ',')}; printComma = true
b = append(b, "\"{{.FieldName}}\":true"...)
b = append(b, "\"{{.FieldName}}\":"...)
b = strconv.AppendBool(b, m.{{.FieldName}})
{{ if not .AllowZeroValue -}}
}
{{- end }}
Expand Down
87 changes: 58 additions & 29 deletions pkg/util/log/eventpb/json_encode_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d1cde5

Please sign in to comment.