log: replace tmp with bytes.Buffer.AvailableBuffer (#29287)
This commit is contained in:
parent
15eb9773f9
commit
ac6060a4c6
@ -79,24 +79,18 @@ func (h *TerminalHandler) format(buf []byte, r slog.Record, usecolor bool) []byt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *TerminalHandler) formatAttributes(buf *bytes.Buffer, r slog.Record, color string) {
|
func (h *TerminalHandler) formatAttributes(buf *bytes.Buffer, r slog.Record, color string) {
|
||||||
// tmp is a temporary buffer we use, until bytes.Buffer.AvailableBuffer() (1.21)
|
|
||||||
// can be used.
|
|
||||||
var tmp = make([]byte, 40)
|
|
||||||
writeAttr := func(attr slog.Attr, first, last bool) {
|
writeAttr := func(attr slog.Attr, first, last bool) {
|
||||||
buf.WriteByte(' ')
|
buf.WriteByte(' ')
|
||||||
|
|
||||||
if color != "" {
|
if color != "" {
|
||||||
buf.WriteString(color)
|
buf.WriteString(color)
|
||||||
//buf.Write(appendEscapeString(buf.AvailableBuffer(), attr.Key))
|
buf.Write(appendEscapeString(buf.AvailableBuffer(), attr.Key))
|
||||||
buf.Write(appendEscapeString(tmp[:0], attr.Key))
|
|
||||||
buf.WriteString("\x1b[0m=")
|
buf.WriteString("\x1b[0m=")
|
||||||
} else {
|
} else {
|
||||||
//buf.Write(appendEscapeString(buf.AvailableBuffer(), attr.Key))
|
buf.Write(appendEscapeString(buf.AvailableBuffer(), attr.Key))
|
||||||
buf.Write(appendEscapeString(tmp[:0], attr.Key))
|
|
||||||
buf.WriteByte('=')
|
buf.WriteByte('=')
|
||||||
}
|
}
|
||||||
//val := FormatSlogValue(attr.Value, true, buf.AvailableBuffer())
|
val := FormatSlogValue(attr.Value, buf.AvailableBuffer())
|
||||||
val := FormatSlogValue(attr.Value, tmp[:0])
|
|
||||||
|
|
||||||
padding := h.fieldPadding[attr.Key]
|
padding := h.fieldPadding[attr.Key]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user