package log import ( "context" "io" "time" kitlog "github.com/go-kit/log" "tildegit.org/tjp/gus" ) func Requests(out io.Writer, logger kitlog.Logger) gus.Middleware { if logger == nil { logger = kitlog.NewLogfmtLogger(kitlog.NewSyncWriter(out)) } return func(next gus.Handler) gus.Handler { return func(ctx context.Context, r *gus.Request) (resp *gus.Response) { start := time.Now() defer func() { end := time.Now() logger.Log( "msg", "request", "ts", end, "dur", end.Sub(start), "url", r.URL, "status", resp.Status, ) }() return next(ctx, r) } } }