Skip to content

Commit

Permalink
refactor(log): TypeOf returns a Lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR4N committed Feb 24, 2025
1 parent d3101d1 commit 87e1ff7
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions log/value.libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ import (
"golang.org/x/exp/slog"
)

// TypeOf returns a LogValuer that reports the concrete type of `v` as
// determined with the `%T` [fmt] verb.
func TypeOf(v any) slog.LogValuer {
return concreteTypeValue{v}
}

type concreteTypeValue struct{ v any }

func (v concreteTypeValue) LogValue() slog.Value {
return slog.StringValue(fmt.Sprintf("%T", v.v))
}

// A Lazy function defers its execution until and if logging is performed.
type Lazy func() slog.Value

Expand All @@ -43,3 +31,11 @@ var _ slog.LogValuer = Lazy(nil)
func (l Lazy) LogValue() slog.Value {
return l()
}

// TypeOf returns a Lazy function that reports the concrete type of `v` as
// determined with the `%T` [fmt] verb.
func TypeOf(v any) Lazy {
return Lazy(func() slog.Value {
return slog.StringValue(fmt.Sprintf("%T", v))
})
}

0 comments on commit 87e1ff7

Please sign in to comment.