diff --git a/logging/logging.go b/logging/logging.go index 043d981..a9e1e3c 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -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) { diff --git a/sentinel/sentinel.go b/sentinel/sentinel.go index a4df9c3..37b93e1 100644 --- a/sentinel/sentinel.go +++ b/sentinel/sentinel.go @@ -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 },