v1.1.0
This commit is contained in:
parent
2666959122
commit
84f521b43d
@ -25,7 +25,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ redis.ConnWithTimeout = (*loggingConn)(nil)
|
||||
_ redis.ConnWithTimeout = (*loggingConn)(nil)
|
||||
logCallDepth = 3
|
||||
)
|
||||
|
||||
// NewLoggingConn returns a logging wrapper around a connection.
|
||||
@ -55,7 +56,7 @@ func (c *loggingConn) Close() error {
|
||||
err := c.Conn.Close()
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintf(&buf, "%sClose() -> (%v)", c.prefix, err)
|
||||
c.logger.Output(2, buf.String()) // nolint: errcheck
|
||||
c.logger.Output(logCallDepth, buf.String()) // nolint: errcheck
|
||||
return err
|
||||
}
|
||||
|
||||
@ -115,7 +116,7 @@ func (c *loggingConn) print(method, commandName string, args []interface{}, repl
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
fmt.Fprintf(&buf, "%v)", err)
|
||||
c.logger.Output(3, buf.String()) // nolint: errcheck
|
||||
c.logger.Output(logCallDepth+1, buf.String()) // nolint: errcheck
|
||||
}
|
||||
|
||||
func (c *loggingConn) Do(commandName string, args ...interface{}) (interface{}, error) {
|
||||
|
@ -93,6 +93,13 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
*cfg.MaxActive = 100
|
||||
}
|
||||
|
||||
var (
|
||||
logPrefix = "redis"
|
||||
logStdPrefix = "DBUG "
|
||||
logStdWriter = os.Stdout
|
||||
logStdFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||
logStdLogger = log.New(logStdWriter, logStdPrefix, logStdFlags)
|
||||
)
|
||||
return &redis.Pool{
|
||||
MaxIdle: *cfg.MaxIdle,
|
||||
MaxActive: *cfg.MaxActive,
|
||||
@ -122,7 +129,7 @@ func NewPool(cfg Config) *redis.Pool {
|
||||
}
|
||||
|
||||
if cfg.Debug {
|
||||
c = logging.NewLoggingConn(c, log.New(os.Stdout, "XXXXXXX", log.LstdFlags), "coreredis")
|
||||
c = logging.NewLoggingConn(c, logStdLogger, logPrefix)
|
||||
}
|
||||
return c, nil
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user