Skip to content

Commit

Permalink
log: add Handler getter to Logger interface (ethereum#28793)
Browse files Browse the repository at this point in the history
log: Add Handler getter to Logger interface
  • Loading branch information
sebastianst committed Mar 7, 2024
1 parent cd49060 commit c41105c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/testlog/testlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func LoggerWithHandler(t *testing.T, handler slog.Handler) log.Logger {
}
}

func (l *logger) Handler() slog.Handler {
return l.l.Handler()
}

func (l *logger) Write(level slog.Level, msg string, ctx ...interface{}) {}

func (l *logger) Enabled(ctx context.Context, level slog.Level) bool {
Expand Down
7 changes: 7 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ type Logger interface {

// Enabled reports whether l emits log records at the given context and level.
Enabled(ctx context.Context, level slog.Level) bool

// Handler returns the underlying handler of the inner logger.
Handler() slog.Handler
}

type logger struct {
Expand All @@ -150,6 +153,10 @@ func NewLogger(h slog.Handler) Logger {
}
}

func (l *logger) Handler() slog.Handler {
return l.inner.Handler()
}

// write logs a message at the specified level:
func (l *logger) Write(level slog.Level, msg string, attrs ...any) {
if !l.inner.Enabled(context.Background(), level) {
Expand Down

0 comments on commit c41105c

Please sign in to comment.