mirror of https://github.com/jackc/pgx.git
Finish compatible interface to inconshreveable/log15
parent
98109c57bb
commit
ff905fe862
2
conn.go
2
conn.go
|
@ -188,7 +188,7 @@ func Connect(config ConnConfig) (c *Conn, err error) {
|
||||||
}
|
}
|
||||||
case readyForQuery:
|
case readyForQuery:
|
||||||
c.rxReadyForQuery(r)
|
c.rxReadyForQuery(r)
|
||||||
c.logger = c.logger.New("pid", c.Pid)
|
c.logger = &connLogger{logger: c.logger, pid: c.Pid}
|
||||||
c.logger.Info("Connection established")
|
c.logger.Info("Connection established")
|
||||||
return c, nil
|
return c, nil
|
||||||
default:
|
default:
|
||||||
|
|
34
logger.go
34
logger.go
|
@ -5,9 +5,6 @@ package pgx
|
||||||
// This logging interface was extracted from there. However, it should be simple
|
// This logging interface was extracted from there. However, it should be simple
|
||||||
// to adapt any logger to this interface.
|
// to adapt any logger to this interface.
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
// New returns a new Logger that has this logger's context plus the given context
|
|
||||||
New(ctx ...interface{}) Logger
|
|
||||||
|
|
||||||
// Log a message at the given level with context key/value pairs
|
// Log a message at the given level with context key/value pairs
|
||||||
Debug(msg string, ctx ...interface{})
|
Debug(msg string, ctx ...interface{})
|
||||||
Info(msg string, ctx ...interface{})
|
Info(msg string, ctx ...interface{})
|
||||||
|
@ -18,9 +15,38 @@ type Logger interface {
|
||||||
|
|
||||||
type DiscardLogger struct{}
|
type DiscardLogger struct{}
|
||||||
|
|
||||||
func (l *DiscardLogger) New(ctx ...interface{}) Logger { return l }
|
|
||||||
func (l *DiscardLogger) Debug(msg string, ctx ...interface{}) {}
|
func (l *DiscardLogger) Debug(msg string, ctx ...interface{}) {}
|
||||||
func (l *DiscardLogger) Info(msg string, ctx ...interface{}) {}
|
func (l *DiscardLogger) Info(msg string, ctx ...interface{}) {}
|
||||||
func (l *DiscardLogger) Warn(msg string, ctx ...interface{}) {}
|
func (l *DiscardLogger) Warn(msg string, ctx ...interface{}) {}
|
||||||
func (l *DiscardLogger) Error(msg string, ctx ...interface{}) {}
|
func (l *DiscardLogger) Error(msg string, ctx ...interface{}) {}
|
||||||
func (l *DiscardLogger) Crit(msg string, ctx ...interface{}) {}
|
func (l *DiscardLogger) Crit(msg string, ctx ...interface{}) {}
|
||||||
|
|
||||||
|
type connLogger struct {
|
||||||
|
logger Logger
|
||||||
|
pid int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *connLogger) Debug(msg string, ctx ...interface{}) {
|
||||||
|
ctx = append(ctx, "pid", l.pid)
|
||||||
|
l.logger.Debug(msg, ctx...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *connLogger) Info(msg string, ctx ...interface{}) {
|
||||||
|
ctx = append(ctx, "pid", l.pid)
|
||||||
|
l.logger.Info(msg, ctx...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *connLogger) Warn(msg string, ctx ...interface{}) {
|
||||||
|
ctx = append(ctx, "pid", l.pid)
|
||||||
|
l.logger.Warn(msg, ctx...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *connLogger) Error(msg string, ctx ...interface{}) {
|
||||||
|
ctx = append(ctx, "pid", l.pid)
|
||||||
|
l.logger.Error(msg, ctx...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *connLogger) Crit(msg string, ctx ...interface{}) {
|
||||||
|
ctx = append(ctx, "pid", l.pid)
|
||||||
|
l.logger.Crit(msg, ctx...)
|
||||||
|
}
|
||||||
|
|
3
query.go
3
query.go
|
@ -3,7 +3,6 @@ package pgx
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "gopkg.in/inconshreveable/log15.v2"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ type Rows struct {
|
||||||
startTime time.Time
|
startTime time.Time
|
||||||
sql string
|
sql string
|
||||||
args []interface{}
|
args []interface{}
|
||||||
logger log.Logger
|
logger Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rows *Rows) FieldDescriptions() []FieldDescription {
|
func (rows *Rows) FieldDescriptions() []FieldDescription {
|
||||||
|
|
Loading…
Reference in New Issue