package maintnotifications
import (
"context"
"slices"
"github.com/redis/go-redis/v9/internal"
"github.com/redis/go-redis/v9/internal/maintnotifications/logs"
"github.com/redis/go-redis/v9/internal/pool"
"github.com/redis/go-redis/v9/push"
)
type LoggingHook struct {
LogLevel int
}
func (lh *LoggingHook ) PreHook (ctx context .Context , notificationCtx push .NotificationHandlerContext , notificationType string , notification []interface {}) ([]interface {}, bool ) {
if lh .LogLevel >= 2 {
connID := uint64 (0 )
if conn , ok := notificationCtx .Conn .(*pool .Conn ); ok {
connID = conn .GetID ()
}
seqID := int64 (0 )
if slices .Contains (maintenanceNotificationTypes , notificationType ) {
if len (notification ) > 1 {
if parsedSeqID , ok := notification [1 ].(int64 ); !ok {
seqID = 0
} else {
seqID = parsedSeqID
}
}
}
internal .Logger .Printf (ctx , "%s" , logs .ProcessingNotification (connID , seqID , notificationType , notification ))
}
return notification , true
}
func (lh *LoggingHook ) PostHook (ctx context .Context , notificationCtx push .NotificationHandlerContext , notificationType string , notification []interface {}, result error ) {
connID := uint64 (0 )
if conn , ok := notificationCtx .Conn .(*pool .Conn ); ok {
connID = conn .GetID ()
}
if result != nil && lh .LogLevel >= 1 {
internal .Logger .Printf (ctx , "%s" , logs .ProcessingNotificationFailed (connID , notificationType , result , notification ))
} else if lh .LogLevel >= 3 {
internal .Logger .Printf (ctx , "%s" , logs .ProcessingNotificationSucceeded (connID , notificationType ))
}
}
func NewLoggingHook (logLevel int ) *LoggingHook {
return &LoggingHook {LogLevel : logLevel }
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .