log: add Handler getter to Logger interface (#28793)
log: Add Handler getter to Logger interface
This commit is contained in:
parent
cd490608e3
commit
c41105ce80
@ -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) Write(level slog.Level, msg string, ctx ...interface{}) {}
|
||||||
|
|
||||||
func (l *logger) Enabled(ctx context.Context, level slog.Level) bool {
|
func (l *logger) Enabled(ctx context.Context, level slog.Level) bool {
|
||||||
|
@ -137,6 +137,9 @@ type Logger interface {
|
|||||||
|
|
||||||
// Enabled reports whether l emits log records at the given context and level.
|
// Enabled reports whether l emits log records at the given context and level.
|
||||||
Enabled(ctx context.Context, level slog.Level) bool
|
Enabled(ctx context.Context, level slog.Level) bool
|
||||||
|
|
||||||
|
// Handler returns the underlying handler of the inner logger.
|
||||||
|
Handler() slog.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
type logger struct {
|
type logger struct {
|
||||||
@ -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:
|
// write logs a message at the specified level:
|
||||||
func (l *logger) Write(level slog.Level, msg string, attrs ...any) {
|
func (l *logger) Write(level slog.Level, msg string, attrs ...any) {
|
||||||
if !l.inner.Enabled(context.Background(), level) {
|
if !l.inner.Enabled(context.Background(), level) {
|
||||||
|
Loading…
Reference in New Issue
Block a user