@@ -13,6 +13,30 @@ import (
13
13
"github.com/signalfx/golib/v3/zkplus/zktest"
14
14
)
15
15
16
+ const (
17
+ // DEBUG all the annoying zk message
18
+ DEBUG = iota
19
+ // NORMAL enough to be useful (he says)
20
+ NORMAL
21
+ )
22
+
23
+ // LogLevel sets the log level of this module
24
+ // I'm sorry to have to put this here but i just can't deal with rewriting the entire
25
+ // log library or swapping it out for zap at the moment. sorry.
26
+ var LogLevel = NORMAL
27
+
28
+ func normalit (logger log.Logger , keyvals ... interface {}) {
29
+ if LogLevel <= NORMAL {
30
+ logger .Log (keyvals ... )
31
+ }
32
+ }
33
+
34
+ func debugit (logger log.Logger , keyvals ... interface {}) {
35
+ if LogLevel <= DEBUG {
36
+ logger .Log (keyvals ... )
37
+ }
38
+ }
39
+
16
40
// ZkConnector tells ZkPlus how to create a zk connection
17
41
type ZkConnector interface {
18
42
Conn () (zktest.ZkConnSupported , <- chan zk.Event , error )
@@ -129,7 +153,7 @@ func (z *ZkPlus) eventLoop() {
129
153
for {
130
154
select {
131
155
case eventToSend = <- whenI (! haveEventToSend && z .connectedChan != nil , z .connectedChan ):
132
- z .logger . Log ( logkey .ZkEvent , eventToSend , logkey .ZkPrefix , z .pathPrefix , log .Msg , "ZK node modification event" )
156
+ normalit ( z .logger , logkey .ZkEvent , eventToSend , logkey .ZkPrefix , z .pathPrefix , log .Msg , "ZK node modification event" )
133
157
if strings .HasPrefix (eventToSend .Path , z .pathPrefix ) {
134
158
eventToSend .Path = eventToSend .Path [len (z .pathPrefix ):]
135
159
if eventToSend .Path == "" {
@@ -158,7 +182,7 @@ func (z *ZkPlus) onQuit(c chan struct{}) {
158
182
z .connectedConn .Close ()
159
183
z .connectedConn = nil
160
184
}
161
- z .logger . Log ( "Close on event loop" )
185
+ normalit ( z .logger , "Close on event loop" )
162
186
}
163
187
164
188
func (z * ZkPlus ) setupConn () {
@@ -169,7 +193,7 @@ func (z *ZkPlus) setupConn() {
169
193
z .connectedConn = c
170
194
z .connectedChan = e
171
195
if err := z .ensureRootPath (c ); err != nil {
172
- z .logger . Log ( "err" , err , "Unable to ensure root path" )
196
+ normalit ( z .logger , "err" , err , "Unable to ensure root path" )
173
197
z .connectedConn .Close ()
174
198
z .connectedConn = nil
175
199
z .connectedChan = nil
@@ -205,50 +229,50 @@ func (z *ZkPlus) blockOnConn() zktest.ZkConnSupported {
205
229
206
230
// Exists returns true if the path exists
207
231
func (z * ZkPlus ) Exists (path string ) (bool , * zk.Stat , error ) {
208
- z .forPath (path ). Log ( logkey .ZkMethod , "Exists" )
232
+ debugit ( z .forPath (path ), logkey .ZkMethod , "Exists" )
209
233
return z .blockOnConn ().Exists (z .realPath (path ))
210
234
}
211
235
212
236
// ExistsW is like Exists but also sets a watch. Note: We DO NOT change paths on the returned
213
237
// channel nor do we reconnect it. Use the global channel instead
214
238
func (z * ZkPlus ) ExistsW (path string ) (bool , * zk.Stat , <- chan zk.Event , error ) {
215
- z .forPath (path ). Log ( logkey .ZkMethod , "ExistsW" )
239
+ debugit ( z .forPath (path ), logkey .ZkMethod , "ExistsW" )
216
240
return z .blockOnConn ().ExistsW (z .realPath (path ))
217
241
}
218
242
219
243
// Get the bytes of a zk path
220
244
func (z * ZkPlus ) Get (path string ) ([]byte , * zk.Stat , error ) {
221
- z .forPath (path ). Log ( logkey .ZkMethod , "Get" )
245
+ debugit ( z .forPath (path ), logkey .ZkMethod , "Get" )
222
246
return z .blockOnConn ().Get (z .realPath (path ))
223
247
}
224
248
225
249
// GetW is like Get, but also sets a watch
226
250
func (z * ZkPlus ) GetW (path string ) ([]byte , * zk.Stat , <- chan zk.Event , error ) {
227
- z .forPath (path ). Log ( logkey .ZkMethod , "GetW" )
251
+ debugit ( z .forPath (path ), logkey .ZkMethod , "GetW" )
228
252
return z .blockOnConn ().GetW (z .realPath (path ))
229
253
}
230
254
231
255
// Children gets children of a path
232
256
func (z * ZkPlus ) Children (path string ) ([]string , * zk.Stat , error ) {
233
- z .forPath (path ). Log ( logkey .ZkMethod , "Children" )
257
+ debugit ( z .forPath (path ), logkey .ZkMethod , "Children" )
234
258
return z .blockOnConn ().Children (z .realPath (path ))
235
259
}
236
260
237
261
// ChildrenW is like children but also sets a watch
238
262
func (z * ZkPlus ) ChildrenW (path string ) ([]string , * zk.Stat , <- chan zk.Event , error ) {
239
- z .forPath (path ). Log ( logkey .ZkMethod , "ChildrenW" )
263
+ debugit ( z .forPath (path ), logkey .ZkMethod , "ChildrenW" )
240
264
return z .blockOnConn ().ChildrenW (z .realPath (path ))
241
265
}
242
266
243
267
// Delete a Zk node
244
268
func (z * ZkPlus ) Delete (path string , version int32 ) error {
245
- z .forPath (path ). Log ( logkey .ZkMethod , "Delete" )
269
+ normalit ( z .forPath (path ), logkey .ZkMethod , "Delete" )
246
270
return z .blockOnConn ().Delete (z .realPath (path ), version )
247
271
}
248
272
249
273
// Create a Zk node
250
274
func (z * ZkPlus ) Create (path string , data []byte , flags int32 , acl []zk.ACL ) (string , error ) {
251
- z .forPath (path ). Log ( logkey .ZkMethod , "Create" )
275
+ normalit ( z .forPath (path ), logkey .ZkMethod , "Create" )
252
276
p , err := z .blockOnConn ().Create (z .realPath (path ), data , flags , acl )
253
277
if strings .HasPrefix (p , z .pathPrefix ) && z .pathPrefix != "" {
254
278
p = p [len (z .pathPrefix )+ 1 :]
@@ -258,7 +282,7 @@ func (z *ZkPlus) Create(path string, data []byte, flags int32, acl []zk.ACL) (st
258
282
259
283
// Set the data of a zk node
260
284
func (z * ZkPlus ) Set (path string , data []byte , version int32 ) (* zk.Stat , error ) {
261
- z .forPath (path ). Log ( logkey .ZkMethod , "Set" )
285
+ normalit ( z .forPath (path ), logkey .ZkMethod , "Set" )
262
286
return z .blockOnConn ().Set (z .realPath (path ), data , version )
263
287
}
264
288
0 commit comments