Skip to content

Commit

Permalink
quic/qlog: don't output empty slog.Attrs
Browse files Browse the repository at this point in the history
For golang/go#58547

Change-Id: I49a27ab82781c817511c6f7da0268529abc3f27f
Reviewed-on: https://go-review.googlesource.com/c/net/+/564015
Reviewed-by: Jonathan Amsterdam <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
neild committed Feb 14, 2024
1 parent 5a444b4 commit 840656f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/quic/qlog/json_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func (w *jsonWriter) writeRecordEnd() {
func (w *jsonWriter) writeAttrs(attrs []slog.Attr) {
w.buf.WriteByte('{')
for _, a := range attrs {
if a.Key == "" {
continue
}
w.writeAttr(a)
}
w.buf.WriteByte('}')
}

func (w *jsonWriter) writeAttr(a slog.Attr) {
if a.Key == "" {
return
}
w.writeName(a.Key)
w.writeValue(a.Value)
}
Expand Down
9 changes: 9 additions & 0 deletions internal/quic/qlog/json_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ func TestJSONWriterAttrs(t *testing.T) {
`}}`)
}

func TestJSONWriterAttrEmpty(t *testing.T) {
w := newTestJSONWriter()
w.writeRecordStart()
var a slog.Attr
w.writeAttr(a)
w.writeRecordEnd()
wantJSONRecord(t, w, `{}`)
}

func TestJSONWriterObjectEmpty(t *testing.T) {
w := newTestJSONWriter()
w.writeRecordStart()
Expand Down

0 comments on commit 840656f

Please sign in to comment.