Files
query-orchestration/internal/serviceconfig/logger/testlogger.go
T
Michael McGuinness f5061f53db Merged in feature/timeout (pull request #138)
Remove race conditions from -race in tests

* timeout

* raceconditions

* nobuildgp

* build

* perf
2025-05-12 15:11:50 +00:00

41 lines
664 B
Go

package logger
import (
"context"
"log/slog"
"sync"
"testing"
)
type TestLogger struct {
T *testing.T
Logs []map[string]any
mu sync.Mutex
}
func (l *TestLogger) Handle(ctx context.Context, r slog.Record) error {
attrs := make(map[string]any)
r.Attrs(func(a slog.Attr) bool {
attrs[a.Key] = a.Value.Any()
return true
})
l.mu.Lock()
defer l.mu.Unlock()
l.Logs = append(l.Logs, attrs)
return nil
}
func (l *TestLogger) Enabled(ctx context.Context, level slog.Level) bool {
return true
}
func (l *TestLogger) WithAttrs(attrs []slog.Attr) slog.Handler {
return l
}
func (l *TestLogger) WithGroup(name string) slog.Handler {
return l
}