From 2f03b02fc9c7e0d91d4d38ecfc5c6c0c0d0d58e5 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Thu, 9 Sep 2021 13:08:21 +1000 Subject: [PATCH] fix(session): handle redis logging properly (#2350) This catches redis logs and displays them via our logging utility. --- internal/session/provider_config.go | 3 +++ internal/session/types.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/session/provider_config.go b/internal/session/provider_config.go index e7ea52283..70ec4621a 100644 --- a/internal/session/provider_config.go +++ b/internal/session/provider_config.go @@ -11,6 +11,7 @@ import ( "github.com/valyala/fasthttp" "github.com/authelia/authelia/v4/internal/configuration/schema" + "github.com/authelia/authelia/v4/internal/logging" "github.com/authelia/authelia/v4/internal/utils" ) @@ -80,6 +81,7 @@ func NewProviderConfig(configuration schema.SessionConfiguration, certPool *x509 providerName = "redis-sentinel" redisSentinelConfig = &redis.FailoverConfig{ + Logger: &redisLogger{logger: logging.Logger()}, MasterName: configuration.Redis.HighAvailability.SentinelName, SentinelAddrs: addrs, SentinelPassword: configuration.Redis.HighAvailability.SentinelPassword, @@ -108,6 +110,7 @@ func NewProviderConfig(configuration schema.SessionConfiguration, certPool *x509 } redisConfig = &redis.Config{ + Logger: newRedisLogger(), Network: network, Addr: addr, Username: configuration.Redis.Username, diff --git a/internal/session/types.go b/internal/session/types.go index 877975136..0dc6ed167 100644 --- a/internal/session/types.go +++ b/internal/session/types.go @@ -1,14 +1,17 @@ package session import ( + "context" "time" "github.com/fasthttp/session/v2" "github.com/fasthttp/session/v2/providers/redis" + "github.com/sirupsen/logrus" "github.com/tstranex/u2f" "github.com/authelia/authelia/v4/internal/authentication" "github.com/authelia/authelia/v4/internal/authorization" + "github.com/authelia/authelia/v4/internal/logging" ) // ProviderConfig is the configuration used to create the session provider. @@ -75,3 +78,15 @@ type OIDCWorkflowSession struct { RequiredAuthorizationLevel authorization.Level CreatedTimestamp int64 } + +func newRedisLogger() *redisLogger { + return &redisLogger{logger: logging.Logger()} +} + +type redisLogger struct { + logger *logrus.Logger +} + +func (l *redisLogger) Printf(_ context.Context, format string, v ...interface{}) { + l.logger.Tracef(format, v...) +}