support custom logger
Some checks failed
Go / build (push) Has been cancelled

This commit is contained in:
finley
2024-10-04 15:28:33 +08:00
parent 705b9721d8
commit fa14a01c88
3 changed files with 65 additions and 6 deletions

View File

@@ -27,7 +27,7 @@ type DelayQueue struct {
garbageKey string // set: message id
useHashTag bool
ticker *time.Ticker
logger *log.Logger
logger Logger
close chan struct{}
running int32
maxConsumeDuration time.Duration // default 5 seconds
@@ -82,6 +82,11 @@ type RedisCli interface {
EvalSha(sha1 string, keys []string, args []interface{}) (interface{}, error)
}
// Logger is an abstraction of logging system
type Logger interface {
Printf(format string, v ...interface{})
}
type hashTagKeyOpt int
// CallbackFunc receives and consumes messages
@@ -153,7 +158,7 @@ func (q *DelayQueue) WithCallback(callback CallbackFunc) *DelayQueue {
}
// WithLogger customizes logger for queue
func (q *DelayQueue) WithLogger(logger *log.Logger) *DelayQueue {
func (q *DelayQueue) WithLogger(logger Logger) *DelayQueue {
q.logger = logger
return q
}