mirror of https://github.com/go-redis/redis.git
Merge 59b477c139
into 930d904205
This commit is contained in:
commit
4c25c04307
|
@ -7,8 +7,15 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
// msg is the main log message.
|
||||
// keysAndValues are the extra context you want to add to your log entries.
|
||||
// To provide additional information for the context in which the log entry was created.
|
||||
// These are passed as variadic arguments so you can pass any number of them.
|
||||
|
||||
type Logging interface {
|
||||
Printf(ctx context.Context, format string, v ...interface{})
|
||||
Info(ctx context.Context, msg string, keysAndValues ...interface{})
|
||||
Error(ctx context.Context, msg string, keysAndValues ...interface{})
|
||||
}
|
||||
|
||||
type logger struct {
|
||||
|
@ -18,6 +25,13 @@ type logger struct {
|
|||
func (l *logger) Printf(ctx context.Context, format string, v ...interface{}) {
|
||||
_ = l.log.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
func (l *logger) Info(ctx context.Context, msg string, keysAndValues ...interface{}) {
|
||||
_ = l.log.Output(2, fmt.Sprintf(msg, keysAndValues...))
|
||||
}
|
||||
|
||||
func (l *logger) Error(ctx context.Context, msg string, keysAndValues ...interface{}) {
|
||||
_ = l.log.Output(2, fmt.Sprintf("ERROR: "+msg, keysAndValues...))
|
||||
}
|
||||
|
||||
// Logger calls Output to print to the stderr.
|
||||
// Arguments are handled in the manner of fmt.Print.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package redis
|
||||
|
||||
// Example : You can use ZapLogger in the following way :
|
||||
// import (
|
||||
// "context"
|
||||
// "fmt"
|
||||
// "go.uber.org/zap"
|
||||
// )
|
||||
//
|
||||
// type ZapLogger struct {
|
||||
// logger *zap.Logger
|
||||
// }
|
||||
//
|
||||
// func NewZapLogger() (*ZapLogger, error) {
|
||||
// logger, err := zap.NewProduction()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// return &ZapLogger{
|
||||
// logger: logger,
|
||||
// }, nil
|
||||
// }
|
||||
//
|
||||
// func (z *ZapLogger) Printf(ctx context.Context, format string, v ...interface{}) {
|
||||
// z.logger.Info(fmt.Sprintf(format, v...))
|
||||
// }
|
||||
//
|
||||
// func (z *ZapLogger) Info(ctx context.Context, msg string, keysAndValues ...interface{}) {
|
||||
// z.logger.Info(fmt.Sprintf(msg, keysAndValues...))
|
||||
// }
|
||||
//
|
||||
// func (z *ZapLogger) Error(ctx context.Context, msg string, keysAndValues ...interface{}) {
|
||||
// z.logger.Error(fmt.Sprintf(msg, keysAndValues...))
|
||||
// }
|
Loading…
Reference in New Issue