2021-01-18 19:00:32 +00:00
|
|
|
package funcs
|
|
|
|
|
|
|
|
import (
|
2021-02-14 10:58:51 +00:00
|
|
|
"context"
|
2021-01-18 19:00:32 +00:00
|
|
|
|
2021-02-14 10:58:51 +00:00
|
|
|
"github.com/jackc/pgx/v4"
|
2021-01-18 19:00:32 +00:00
|
|
|
"github.com/phuslu/log"
|
|
|
|
)
|
|
|
|
|
2021-02-14 10:58:51 +00:00
|
|
|
//PGXLogger is an struct to intergrate the Logger Interface of pgx
|
|
|
|
type PGXLogger struct{}
|
2021-01-18 19:00:32 +00:00
|
|
|
|
2021-02-14 10:58:51 +00:00
|
|
|
// Log sends the logging data to phuslu/log
|
|
|
|
func (PGXLogger) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) {
|
|
|
|
var entry *log.Entry
|
|
|
|
switch level {
|
|
|
|
case pgx.LogLevelDebug:
|
|
|
|
entry = log.Debug()
|
|
|
|
case pgx.LogLevelError:
|
|
|
|
entry = log.Error()
|
|
|
|
case pgx.LogLevelInfo:
|
|
|
|
entry = log.Info()
|
|
|
|
case pgx.LogLevelTrace:
|
|
|
|
entry = log.Trace()
|
|
|
|
case pgx.LogLevelWarn:
|
|
|
|
entry = log.Warn()
|
|
|
|
default:
|
|
|
|
entry = log.Info()
|
|
|
|
}
|
|
|
|
for key, value := range data {
|
|
|
|
entry = entry.Interface(key, value)
|
|
|
|
}
|
|
|
|
entry.Msg(msg)
|
2021-01-18 19:00:32 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 10:58:51 +00:00
|
|
|
var _ pgx.Logger = PGXLogger{}
|