File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ func NewWorker(opts ...Option) *Worker {
4444 panic (err )
4545 }
4646
47+ w .p .SetLoggerLevel (nsq .LogLevel (w .opts .logLvl ))
48+
4749 return w
4850}
4951
@@ -62,6 +64,8 @@ func (w *Worker) startConsumer() (err error) {
6264 return
6365 }
6466
67+ w .q .SetLoggerLevel (nsq .LogLevel (w .opts .logLvl ))
68+
6569 w .q .AddHandler (nsq .HandlerFunc (func (msg * nsq.Message ) error {
6670 if len (msg .Body ) == 0 {
6771 // Returning nil will automatically send a FIN command to NSQ to mark the message as processed.
Original file line number Diff line number Diff line change @@ -5,6 +5,17 @@ import (
55
66 "github.com/golang-queue/queue"
77 "github.com/golang-queue/queue/core"
8+
9+ nsq "github.com/nsqio/go-nsq"
10+ )
11+
12+ // Log levels (same as [nsq.LogLevel])
13+ const (
14+ LogLevelDebug nsq.LogLevel = iota
15+ LogLevelInfo
16+ LogLevelWarning
17+ LogLevelError
18+ LogLevelMax = iota - 1 // convenience - match highest log level
819)
920
1021// An Option configures a mutex.
@@ -27,6 +38,7 @@ type Options struct {
2738 channel string
2839 runFunc func (context.Context , core.QueuedMessage ) error
2940 logger queue.Logger
41+ logLvl nsq.LogLevel
3042}
3143
3244// WithAddr setup the addr of NSQ
@@ -71,6 +83,13 @@ func WithLogger(l queue.Logger) Option {
7183 })
7284}
7385
86+ // WithLogLevel set custom [nsq] log level
87+ func WithLogLevel (lvl nsq.LogLevel ) Option {
88+ return OptionFunc (func (o * Options ) {
89+ o .logLvl = lvl
90+ })
91+ }
92+
7493func newOptions (opts ... Option ) Options {
7594 defaultOpts := Options {
7695 addr : "127.0.0.1:4150" ,
@@ -79,6 +98,7 @@ func newOptions(opts ...Option) Options {
7998 maxInFlight : 1 ,
8099
81100 logger : queue .NewLogger (),
101+ logLvl : LogLevelInfo ,
82102 runFunc : func (context.Context , core.QueuedMessage ) error {
83103 return nil
84104 },
You can’t perform that action at this time.
0 commit comments