Add production features: slog adapter, scan helpers, slow query logging, pool stats, tracer passthrough, test tx isolation
Some checks failed
CI / test (push) Failing after 13s
Some checks failed
CI / test (push) Failing after 13s
- slog.go: SlogLogger adapts *slog.Logger to dbx.Logger interface - scan.go: Collect[T] and CollectOne[T] generic helpers using pgx.RowToStructByName - cluster.go: slow query logging via Config.SlowQueryThreshold (Warn level in queryEnd) - stats.go: PoolStats with Cluster.Stats() aggregating pool stats across all nodes - config.go/node.go: NodeConfig.Tracer passthrough for pgx.QueryTracer (OpenTelemetry) - options.go: WithSlowQueryThreshold and WithTracer functional options - dbxtest/tx.go: RunInTx runs callback in always-rolled-back transaction for test isolation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
38
slog.go
Normal file
38
slog.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package dbx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
// SlogLogger adapts *slog.Logger to the dbx.Logger interface.
|
||||
type SlogLogger struct {
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
// NewSlogLogger creates a SlogLogger. If l is nil, slog.Default() is used.
|
||||
func NewSlogLogger(l *slog.Logger) *SlogLogger {
|
||||
if l == nil {
|
||||
l = slog.Default()
|
||||
}
|
||||
return &SlogLogger{Logger: l}
|
||||
}
|
||||
|
||||
func (s *SlogLogger) Debug(ctx context.Context, msg string, fields ...any) {
|
||||
s.Logger.DebugContext(ctx, msg, fields...)
|
||||
}
|
||||
|
||||
func (s *SlogLogger) Info(ctx context.Context, msg string, fields ...any) {
|
||||
s.Logger.InfoContext(ctx, msg, fields...)
|
||||
}
|
||||
|
||||
func (s *SlogLogger) Warn(ctx context.Context, msg string, fields ...any) {
|
||||
s.Logger.WarnContext(ctx, msg, fields...)
|
||||
}
|
||||
|
||||
func (s *SlogLogger) Error(ctx context.Context, msg string, fields ...any) {
|
||||
s.Logger.ErrorContext(ctx, msg, fields...)
|
||||
}
|
||||
|
||||
// Compile-time check.
|
||||
var _ Logger = (*SlogLogger)(nil)
|
||||
Reference in New Issue
Block a user