package funcs import ( "context" "net" "github.com/jackc/pgx/v4" "github.com/phuslu/log" ) //PGXLogger is an struct to intergrate the Logger Interface of pgx type PGXLogger struct{} // 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) } var _ pgx.Logger = PGXLogger{} // IsUnix tests if the address is an unix address. It returns false if its an tcp address. func IsUnix(address string) bool { if IsTCP(address) { return false } if _, err := net.ResolveUnixAddr("unix", address); err == nil { return true } return false } // IsTCP tests if the address is an tcp address func IsTCP(address string) bool { _, err := net.ResolveTCPAddr("tcp", address) if err == nil { return true } return false }