internal/testlog: reduce code a bit

This commit is contained in:
Martin Holst Swende 2023-11-13 20:11:49 +01:00 committed by Jared Wasinger
parent 8632783dcb
commit 50210133e6

View file

@ -180,18 +180,13 @@ func (h *bufHandler) terminalFormat(r slog.Record) string {
attrs = append(h.attrs, attrs...) attrs = append(h.attrs, attrs...)
fmt.Fprintf(buf, "%s[%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Message) fmt.Fprintf(buf, "%s[%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Message)
if length := len(r.Message); length < 40 {
buf.Write(bytes.Repeat([]byte{' '}, 40-length))
}
for i, attr := range attrs { for _, attr := range attrs {
if i != 0 {
buf.WriteByte(' ')
}
rawVal := attr.Value.Any() rawVal := attr.Value.Any()
val := log.FormatLogfmtValue(rawVal, true) fmt.Fprintf(buf, " %s=%s", attr.Key, log.FormatLogfmtValue(rawVal, true))
buf.WriteString(attr.Key)
buf.WriteByte('=')
buf.WriteString(val)
} }
buf.WriteByte('\n') buf.WriteByte('\n')
return buf.String() return buf.String()