mirror of
https://github.com/redis/go-redis.git
synced 2025-09-05 20:24:00 +03:00
chore(log): add note related to logging and simple void logger
This commit is contained in:
@@ -7,6 +7,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO (ned): Revisit logging
|
||||||
|
// Add more standardized approach with log levels and configurability
|
||||||
|
|
||||||
type Logging interface {
|
type Logging interface {
|
||||||
Printf(ctx context.Context, format string, v ...interface{})
|
Printf(ctx context.Context, format string, v ...interface{})
|
||||||
}
|
}
|
||||||
@@ -24,3 +27,13 @@ func (l *logger) Printf(ctx context.Context, format string, v ...interface{}) {
|
|||||||
var Logger Logging = &logger{
|
var Logger Logging = &logger{
|
||||||
log: log.New(os.Stderr, "redis: ", log.LstdFlags|log.Lshortfile),
|
log: log.New(os.Stderr, "redis: ", log.LstdFlags|log.Lshortfile),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VoidLogger is a logger that does nothing.
|
||||||
|
// Used to disable logging and thus speed up the library.
|
||||||
|
type VoidLogger struct{}
|
||||||
|
|
||||||
|
func (v *VoidLogger) Printf(_ context.Context, _ string, _ ...interface{}) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Logging = (*VoidLogger)(nil)
|
||||||
|
1
redis.go
1
redis.go
@@ -24,6 +24,7 @@ type Scanner = hscan.Scanner
|
|||||||
const Nil = proto.Nil
|
const Nil = proto.Nil
|
||||||
|
|
||||||
// SetLogger set custom log
|
// SetLogger set custom log
|
||||||
|
// Use with VoidLogger to disable logging.
|
||||||
func SetLogger(logger internal.Logging) {
|
func SetLogger(logger internal.Logging) {
|
||||||
internal.Logger = logger
|
internal.Logger = logger
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user