mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
log: avoid using go 1.21-specific features
This commit is contained in:
parent
d2251afece
commit
b7933d28e7
1 changed files with 9 additions and 6 deletions
|
|
@ -95,22 +95,25 @@ func (h *TerminalHandler) TerminalFormat(buf []byte, r slog.Record, usecolor boo
|
|||
}
|
||||
|
||||
func (h *TerminalHandler) logfmt(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) {
|
||||
buf.WriteByte(' ')
|
||||
|
||||
if 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=")
|
||||
} else {
|
||||
buf.Write(appendEscapeString(buf.AvailableBuffer(), attr.Key))
|
||||
//buf.Write(appendEscapeString(buf.AvailableBuffer(), attr.Key))
|
||||
buf.Write(appendEscapeString(tmp[:0], attr.Key))
|
||||
buf.WriteByte('=')
|
||||
}
|
||||
tmp := buf.AvailableBuffer()
|
||||
val := FormatSlogValue(attr.Value, true, tmp)
|
||||
//val := FormatSlogValue(attr.Value, true, buf.AvailableBuffer())
|
||||
val := FormatSlogValue(attr.Value, true, tmp[:0])
|
||||
|
||||
// XXX: we should probably check that all of your key bytes aren't invalid
|
||||
// TODO (jwasinger) above comment was from log15 code. what does it mean? check that key bytes are ascii characters?
|
||||
padding := h.fieldPadding[attr.Key]
|
||||
|
||||
length := utf8.RuneCount(val)
|
||||
|
|
|
|||
Loading…
Reference in a new issue