Skip to content

Commit 0fd4c7d

Browse files
committed
healthcheck: improve logging of observers
1 parent 04dde98 commit 0fd4c7d

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

healthcheck/healthcheck.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,13 @@ func (o *Observation) monitor(shutdown shutdownFunc, quit chan struct{}) {
234234
// the max attempts are reached. In that case we will
235235
// stop the ticker and quit.
236236
if o.retryCheck(quit, shutdown) {
237-
log.Debugf("Health check: max attempts " +
238-
"failed, monitor exiting")
237+
o.Debugf("max attempts failed, monitor exiting")
239238
return
240239
}
241240

242241
// Exit if we receive the instruction to shutdown.
243242
case <-quit:
244-
log.Debug("Health check: monitor quit")
243+
o.Debugf("monitor quit")
245244
return
246245
}
247246
}
@@ -270,7 +269,7 @@ func (o *Observation) retryCheck(quit chan struct{},
270269
// so we'll invoke our success callback if defined and
271270
// then exit.
272271
if err == nil {
273-
log.Debug("invoking success callback")
272+
o.Debugf("invoking success callback")
274273

275274
// Invoke the success callback.
276275
o.OnSuccess()
@@ -283,25 +282,26 @@ func (o *Observation) retryCheck(quit chan struct{},
283282
"%v", o, o.Timeout)
284283

285284
case <-quit:
286-
log.Debug("Health check: monitor quit")
285+
o.Debugf("monitor quit")
287286
return false
288287
}
289288

290289
// If we have reached our allowed number of attempts, this
291290
// check has failed so we'll fire the on failure callback
292291
// and request shutdown.
293292
if count == o.Attempts {
294-
log.Debug("invoking failure callback")
293+
o.Debugf("invoking failure callback")
295294

296295
o.OnFailure()
297296

298-
shutdown("Health check: %v failed after %v "+
299-
"calls", o, o.Attempts)
297+
shutdown("Health check: %v failed after %v calls", o,
298+
o.Attempts)
299+
300300
return true
301301
}
302302

303-
log.Infof("Health check: %v, call: %v failed with: %v, "+
304-
"backing off for: %v", o, count, err, o.Backoff)
303+
o.Infof("failed with: %v, attempts: %v backing off for: %v",
304+
err, count, o.Backoff)
305305

306306
// If we are still within the number of calls allowed for this
307307
// check, we wait for our back off period to elapse, or exit if
@@ -310,10 +310,22 @@ func (o *Observation) retryCheck(quit chan struct{},
310310
case <-time.After(o.Backoff):
311311

312312
case <-quit:
313-
log.Debug("Health check: monitor quit")
313+
o.Debugf("monitor quit")
314314
return false
315315
}
316316
}
317317

318318
return false
319319
}
320+
321+
// Infof logs an info message for an observation prefixed with the health check
322+
// name.
323+
func (o *Observation) Infof(format string, params ...interface{}) {
324+
log.Debugf(fmt.Sprintf("Health check: %v ", o)+format, params...)
325+
}
326+
327+
// Debugf logs a debug message for an observation prefixed with the health check
328+
// name.
329+
func (o *Observation) Debugf(format string, params ...interface{}) {
330+
log.Debugf(fmt.Sprintf("Health check: %v ", o)+format, params...)
331+
}

0 commit comments

Comments
 (0)