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 {
44
44
panic (err )
45
45
}
46
46
47
+ w .p .SetLoggerLevel (nsq .LogLevel (w .opts .logLvl ))
48
+
47
49
return w
48
50
}
49
51
@@ -62,6 +64,8 @@ func (w *Worker) startConsumer() (err error) {
62
64
return
63
65
}
64
66
67
+ w .q .SetLoggerLevel (nsq .LogLevel (w .opts .logLvl ))
68
+
65
69
w .q .AddHandler (nsq .HandlerFunc (func (msg * nsq.Message ) error {
66
70
if len (msg .Body ) == 0 {
67
71
// 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 (
5
5
6
6
"github.com/golang-queue/queue"
7
7
"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
8
19
)
9
20
10
21
// An Option configures a mutex.
@@ -27,6 +38,7 @@ type Options struct {
27
38
channel string
28
39
runFunc func (context.Context , core.QueuedMessage ) error
29
40
logger queue.Logger
41
+ logLvl nsq.LogLevel
30
42
}
31
43
32
44
// WithAddr setup the addr of NSQ
@@ -71,6 +83,13 @@ func WithLogger(l queue.Logger) Option {
71
83
})
72
84
}
73
85
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
+
74
93
func newOptions (opts ... Option ) Options {
75
94
defaultOpts := Options {
76
95
addr : "127.0.0.1:4150" ,
@@ -79,6 +98,7 @@ func newOptions(opts ...Option) Options {
79
98
maxInFlight : 1 ,
80
99
81
100
logger : queue .NewLogger (),
101
+ logLvl : LogLevelInfo ,
82
102
runFunc : func (context.Context , core.QueuedMessage ) error {
83
103
return nil
84
104
},
You can’t perform that action at this time.
0 commit comments