Skip to content

Commit 039a5dd

Browse files
committed
pubsub: pass custom log to pubsub
1 parent f7b3619 commit 039a5dd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pubsub.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ func (c *PubSub) ChannelWithSubscriptions(_ context.Context, size int) <-chan in
470470

471471
type ChannelOption func(c *channel)
472472

473+
func WithLogger(logger internal.Logging) ChannelOption {
474+
return func(c *channel) {
475+
c.logger = logger
476+
}
477+
}
478+
473479
// WithChannelSize specifies the Go chan size that is used to buffer incoming messages.
474480
//
475481
// The default is 100 messages.
@@ -510,6 +516,8 @@ type channel struct {
510516
chanSize int
511517
chanSendTimeout time.Duration
512518
checkInterval time.Duration
519+
520+
logger internal.Logging
513521
}
514522

515523
func newChannel(pubSub *PubSub, opts ...ChannelOption) *channel {
@@ -519,6 +527,7 @@ func newChannel(pubSub *PubSub, opts ...ChannelOption) *channel {
519527
chanSize: 100,
520528
chanSendTimeout: time.Minute,
521529
checkInterval: 3 * time.Second,
530+
logger: internal.Logger,
522531
}
523532
for _, opt := range opts {
524533
opt(c)
@@ -602,12 +611,12 @@ func (c *channel) initMsgChan() {
602611
<-timer.C
603612
}
604613
case <-timer.C:
605-
internal.Logger.Printf(
606-
ctx, "redis: %s channel is full for %s (message is dropped)",
614+
c.logger.Printf(
615+
ctx, "redis: %+v channel is full for %s (message is dropped)",
607616
c, c.chanSendTimeout)
608617
}
609618
default:
610-
internal.Logger.Printf(ctx, "redis: unknown message type: %T", msg)
619+
c.logger.Printf(ctx, "redis: unknown message type: %T", msg)
611620
}
612621
}
613622
}()
@@ -656,12 +665,12 @@ func (c *channel) initAllChan() {
656665
<-timer.C
657666
}
658667
case <-timer.C:
659-
internal.Logger.Printf(
660-
ctx, "redis: %s channel is full for %s (message is dropped)",
668+
c.logger.Printf(
669+
ctx, "redis: %+v channel is full for %s (message is dropped)",
661670
c, c.chanSendTimeout)
662671
}
663672
default:
664-
internal.Logger.Printf(ctx, "redis: unknown message type: %T", msg)
673+
c.logger.Printf(ctx, "redis: unknown message type: %T", msg)
665674
}
666675
}
667676
}()

0 commit comments

Comments
 (0)