From 18b7d3e3c8ff9a51d75a562dd483fe14b5962996 Mon Sep 17 00:00:00 2001 From: Jin Peng <554085731@qq.com> Date: Thu, 7 Nov 2024 14:44:55 +0800 Subject: [PATCH] fix: Fix the bug where the request latency is not correctly output when using the default template. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Associated issue: https://github.com/hertz-contrib/logger/issues/56 --- accesslog/accesslog.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/accesslog/accesslog.go b/accesslog/accesslog.go index ee42929..97f8ac9 100644 --- a/accesslog/accesslog.go +++ b/accesslog/accesslog.go @@ -105,8 +105,6 @@ func new(ctx context.Context, opts ...Option) app.HandlerFunc { } return func(ctx context.Context, c *app.RequestContext) { - var start, stop time.Time - // Logger data data := dataPool.Get().(*Data) //nolint:forcetypeassert,errcheck // We store nothing else in the pool // no need for a reset, as long as we always override everything @@ -139,7 +137,7 @@ func new(ctx context.Context, opts ...Option) app.HandlerFunc { _, _ = buf.WriteString(fmt.Sprintf(defaultFormat, timestamp, c.Response.StatusCode(), - stop.Sub(start), + data.Stop.Sub(data.Start), c.Method(), c.Path(), ))