log: remove unused code

This commit is contained in:
Martin Holst Swende 2023-12-04 12:08:46 +01:00
parent 6e51b148c1
commit 58378e0764
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -2,14 +2,9 @@ package log
import ( import (
"context" "context"
"fmt"
"io" "io"
"math/big"
"reflect"
"sync" "sync"
"time"
"github.com/holiman/uint256"
"golang.org/x/exp/slog" "golang.org/x/exp/slog"
) )
@ -125,64 +120,3 @@ func JSONHandler(wr io.Writer) slog.Handler {
func LogfmtHandler(wr io.Writer) slog.Handler { func LogfmtHandler(wr io.Writer) slog.Handler {
return slog.NewTextHandler(wr, nil) return slog.NewTextHandler(wr, nil)
} }
// LogfmtHandlerWithLevel returns the same handler as LogfmtHandler but it only outputs
// records which are less than or equal to the specified verbosity level.
func LogfmtHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler {
return slog.NewTextHandler(wr, &slog.HandlerOptions{
ReplaceAttr: builtinReplaceLogfmt,
Level: &leveler{level},
})
}
func builtinReplaceLogfmt(_ []string, attr slog.Attr) slog.Attr {
return builtinReplace(nil, attr, true)
}
func builtinReplaceJSON(_ []string, attr slog.Attr) slog.Attr {
return builtinReplace(nil, attr, false)
}
func builtinReplace(_ []string, attr slog.Attr, logfmt bool) slog.Attr {
switch attr.Key {
case slog.TimeKey:
if attr.Value.Kind() == slog.KindTime {
if logfmt {
return slog.String("t", attr.Value.Time().Format(timeFormat))
} else {
return slog.Attr{Key: "t", Value: attr.Value}
}
}
case slog.LevelKey:
if l, ok := attr.Value.Any().(slog.Level); ok {
attr = slog.Any("lvl", LevelString(l))
return attr
}
}
switch v := attr.Value.Any().(type) {
case time.Time:
if logfmt {
attr = slog.String(attr.Key, v.Format(timeFormat))
}
case *big.Int:
if v == nil {
attr.Value = slog.StringValue("<nil>")
} else {
attr.Value = slog.StringValue(v.String())
}
case *uint256.Int:
if v == nil {
attr.Value = slog.StringValue("<nil>")
} else {
attr.Value = slog.StringValue(v.Dec())
}
case fmt.Stringer:
if v == nil || (reflect.ValueOf(v).Kind() == reflect.Pointer && reflect.ValueOf(v).IsNil()) {
attr.Value = slog.StringValue("<nil>")
} else {
attr.Value = slog.StringValue(v.String())
}
}
return attr
}