-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.go
39 lines (33 loc) · 839 Bytes
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package log
import (
"context"
"github.com/go-kit/log"
kitlevel "github.com/go-kit/log/level"
"github.com/jackc/pgx/v5"
)
type Logger struct {
l log.Logger
}
func NewLogger(l log.Logger) *Logger {
return &Logger{l: l}
}
func (l *Logger) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) {
logger := l.l
for k, v := range data {
logger = log.With(logger, k, v)
}
switch level {
case pgx.LogLevelTrace:
logger.Log("PGX_LOG_LEVEL", level, "msg", msg)
case pgx.LogLevelDebug:
kitlevel.Debug(logger).Log("msg", msg)
case pgx.LogLevelInfo:
kitlevel.Info(logger).Log("msg", msg)
case pgx.LogLevelWarn:
kitlevel.Warn(logger).Log("msg", msg)
case pgx.LogLevelError:
kitlevel.Error(logger).Log("msg", msg)
default:
logger.Log("INVALID_PGX_LOG_LEVEL", level, "error", msg)
}
}