add missing parts from previous commit

This commit is contained in:
Jared Wasinger 2023-11-09 19:42:12 +08:00
parent 14bc27f178
commit 5beed9f75d
3 changed files with 3 additions and 5 deletions

View file

@ -73,7 +73,7 @@ type TerminalStringer interface {
// Example:
//
// [DBUG] [May 16 20:58:45] remove route ns=haproxy addr=127.0.0.1:50002
func TerminalFormat(r slog.Record, usecolor bool) []byte {
func TerminalFormat(r slog.Record, commonAttrs []slog.Attr, usecolor bool) []byte {
msg := escapeMessage(r.Message)
var color = 0
if usecolor {
@ -106,7 +106,7 @@ func TerminalFormat(r slog.Record, usecolor bool) []byte {
b.Write(bytes.Repeat([]byte{' '}, termMsgJust-length))
}
// print the keys logfmt style
logfmt(b, []slog.Attr{}, r, color, true)
logfmt(b, commonAttrs, r, color, true)
return b.Bytes()
}

View file

@ -140,8 +140,7 @@ func TerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) slog.
func (h *terminalHandler) Handle(_ context.Context, r slog.Record) error {
h.mu.Lock()
defer h.mu.Unlock()
r.AddAttrs(h.attrs...)
h.wr.Write(TerminalFormat(r, h.useColor))
h.wr.Write(TerminalFormat(r, h.attrs, h.useColor))
return nil
}

View file

@ -5,7 +5,6 @@ import (
"os"
"strings"
"testing"
"golang.org/x/exp/slog"
)