fix(session): handle redis logging properly (#2350)

This catches redis logs and displays them via our logging utility.
pull/2355/head
James Elliott 2021-09-09 13:08:21 +10:00 committed by GitHub
parent f1b2b4d79e
commit 2f03b02fc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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,

View File

@ -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...)
}