From b62fe92276bdd31d2d75297483e40f38e66cf4d7 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Mon, 4 Aug 2025 15:38:06 +0300 Subject: [PATCH] chore(log): add note related to logging and simple void logger --- internal/log.go | 13 +++++++++++++ redis.go | 1 + 2 files changed, 14 insertions(+) diff --git a/internal/log.go b/internal/log.go index c8b9213d..4fe3d7db 100644 --- a/internal/log.go +++ b/internal/log.go @@ -7,6 +7,9 @@ import ( "os" ) +// TODO (ned): Revisit logging +// Add more standardized approach with log levels and configurability + type Logging 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{ 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) diff --git a/redis.go b/redis.go index f1f65712..b3608c5f 100644 --- a/redis.go +++ b/redis.go @@ -24,6 +24,7 @@ type Scanner = hscan.Scanner const Nil = proto.Nil // SetLogger set custom log +// Use with VoidLogger to disable logging. func SetLogger(logger internal.Logging) { internal.Logger = logger }