@@ -464,34 +464,16 @@ func sleepCtx(ctx context.Context, d time.Duration) error {
464
464
return err
465
465
}
466
466
467
- // jsonLogger implements the log.Logger interface.
468
- type jsonLogger struct {
469
- entries []map [string ]string
470
- }
471
-
472
- // Log takes key-value pairs and logs them.
473
- func (l * jsonLogger ) Log (keyvals ... interface {}) error {
474
- m := make (map [string ]string )
475
- if len (keyvals )% 2 != 0 {
476
- return fmt .Errorf ("expected even number of keyvals, got %d" , len (keyvals ))
477
- }
478
- for i := 0 ; i < len (keyvals ); i += 2 {
479
- k := fmt .Sprintf ("%v" , keyvals [i ])
480
- v := fmt .Sprintf ("%v" , keyvals [i + 1 ])
481
- m [k ] = v
482
- }
483
- l .entries = append (l .entries , m )
484
- return nil
485
- }
486
-
487
467
// Run runs the specified prober once and captures the results using
488
468
// jsonLogger.
489
469
func (r * runner ) Run (ctx context.Context , tenantId model.GlobalID , publisher pusher.Publisher ) {
490
470
r .logger .Info ().Msg ("running ad-hoc check" )
491
471
492
472
registry := prometheus .NewRegistry ()
493
473
494
- logger := & jsonLogger {}
474
+ // Create a logger that captures entries for later use
475
+ var logBuf bytes.Buffer
476
+ zlogger := zerolog .New (& logBuf )
495
477
496
478
// TODO(mem): decide what to do with these metrics.
497
479
successGauge := prometheus .NewGauge (prometheus.GaugeOpts {
@@ -513,7 +495,7 @@ func (r *runner) Run(ctx context.Context, tenantId model.GlobalID, publisher pus
513
495
rCtx , cancel := context .WithTimeout (ctx , r .timeout )
514
496
defer cancel ()
515
497
516
- success , duration := r .prober .Probe (rCtx , r .target , registry , logger )
498
+ success , duration := r .prober .Probe (rCtx , r .target , registry , zlogger )
517
499
518
500
if success {
519
501
successGauge .Set (1 )
@@ -538,7 +520,7 @@ func (r *runner) Run(ctx context.Context, tenantId model.GlobalID, publisher pus
538
520
Str ("target" , r .target ).
539
521
Str ("probe" , r .probe ).
540
522
Str ("check_name" , r .prober .Name ()).
541
- Interface ("logs" , logger . entries ).
523
+ Str ("logs" , logBuf . String () ).
542
524
Interface ("timeseries" , mfs ).
543
525
Msg ("ad-hoc check done" )
544
526
0 commit comments