Skip to content

Commit

Permalink
feat(redis): call redis.SetLogger() with the zot logger as parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Aaron <[email protected]>
  • Loading branch information
andaaron committed Jan 30, 2025
1 parent 5aa6f3b commit b880ae6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/api/config/redis/redis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package rediscfg

import (
"context"
"fmt"
"strings"
"sync"
"time"

"github.com/redis/go-redis/v9"
Expand All @@ -12,7 +14,19 @@ import (
"zotregistry.dev/zot/pkg/log"
)

var once sync.Once //nolint: gochecknoglobals // redis.SetLogger modifies an unprotected global variable

type redisLogger struct {
log log.Logger
}

func (r redisLogger) Printf(ctx context.Context, format string, v ...interface{}) {
r.log.Debug().Msgf(format, v...)

Check warning on line 24 in pkg/api/config/redis/redis.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/config/redis/redis.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

func GetRedisClient(redisConfig map[string]interface{}, log log.Logger) (redis.UniversalClient, error) {
once.Do(func() { redis.SetLogger(redisLogger{log}) }) // call redis.SetLogger only once

// go-redis supports connecting via the redis uri specification (more convenient than parameter parsing)
// Note failover/Sentinel cannot be configured via URL parsing at the moment
if val, ok := redisConfig["url"]; ok {
Expand Down

0 comments on commit b880ae6

Please sign in to comment.