Skip to content

Commit

Permalink
optimize: latency use lowest time unit in logger middleware (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jin-gou committed Dec 10, 2022
1 parent a9ddef7 commit efeea7a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions middleware/logger/logger_test.go
Expand Up @@ -13,12 +13,11 @@ import (
"testing"
"time"

"github.com/valyala/bytebufferpool"
"github.com/valyala/fasthttp"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/requestid"
"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/bytebufferpool"
"github.com/valyala/fasthttp"
)

// go test -run Test_Logger
Expand Down
3 changes: 1 addition & 2 deletions middleware/logger/tags.go
Expand Up @@ -3,7 +3,6 @@ package logger
import (
"fmt"
"strings"
"time"

"github.com/gofiber/fiber/v2"
)
Expand Down Expand Up @@ -192,7 +191,7 @@ func createTagMap(cfg *Config) map[string]LogFunc {
return output.WriteString(data.Pid)
},
TagLatency: func(output Buffer, c *fiber.Ctx, data *Data, extraParam string) (int, error) {
latency := data.Stop.Sub(data.Start).Round(time.Millisecond)
latency := data.Stop.Sub(data.Start)
return output.WriteString(fmt.Sprintf("%7v", latency))
},
TagTime: func(output Buffer, c *fiber.Ctx, data *Data, extraParam string) (int, error) {
Expand Down

0 comments on commit efeea7a

Please sign in to comment.