github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/output/hrf/timer.go (about)

     1  package hrf
     2  
     3  import (
     4  	"github.com/v2pro/plz/countlog/spi"
     5  	"time"
     6  )
     7  
     8  type timerFormatter struct {
     9  	idx int
    10  }
    11  
    12  func (formatter *timerFormatter) Format(space []byte, event *spi.Event) []byte {
    13  	latency := event.Timestamp.UnixNano() - event.Properties[formatter.idx].(int64)
    14  	space = append(space, "\ntimer: "...)
    15  	space = append(space, time.Duration(latency).String()...)
    16  	return space
    17  }
    18