-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
Question Description
When I turn on logging I mostly get, logged, that things took 0s. But I really would like to see how many:
- s
- ms
- μs
- ns
it took.
I come from the Gin framework and am very happy how fiber works, but loggin is a little weird tbh. I would like it to display the ${latency} (how long it took to process the request internally) in the smallest time.unit possible but in the biggest needed.
Code Snippet (optional)
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/html"
)
[...]
func main() {
templates := html.New("../templates", ".html")
server := fiber.New(fiber.Config{
CompressedFileSuffix: ".compressed",
UnescapePath: true,
Views: templates,
})
server.Use(logger.New(logger.Config{
Format: "${time} [${ip}] ${status} - ${latency} ${method} ${path}\n",
}))
server.Static("/", "../static", fiber.Static{
Compress: true,
})
server.Get("/", pageMain)
server.Listen(":8003")
}
RESULT:
┌───────────────────────────────────────────────────┐
│ Fiber v2.40.1 │
│ http://127.0.0.1:8003 │
│ (bound on host 0.0.0.0 and port 8003) │
│ │
│ Handlers ............. 4 Processes ........... 1 │
│ Prefork ....... Disabled PID ........... 3980243 │
└───────────────────────────────────────────────────┘
14:42:17 [127.0.0.1] 200 - 0s GET /
14:42:18 [127.0.0.1] 200 - 0s GET /
14:42:18 [127.0.0.1] 200 - 0s GET /
14:42:19 [127.0.0.1] 200 - 0s GET /
14:42:19 [127.0.0.1] 200 - 0s GET /
14:42:19 [127.0.0.1] 200 - 0s GET /
14:42:20 [127.0.0.1] 200 - 0s GET /
14:42:20 [127.0.0.1] 200 - 0s GET /
14:42:20 [127.0.0.1] 200 - 0s GET /
14:42:21 [127.0.0.1] 200 - 0s GET /with standard logging settings it still is like this:
┌───────────────────────────────────────────────────┐
│ Fiber v2.40.1 │
│ http://127.0.0.1:8003 │
│ (bound on host 0.0.0.0 and port 8003) │
│ │
│ Handlers ............. 4 Processes ........... 1 │
│ Prefork ....... Disabled PID ........... 4057659 │
└───────────────────────────────────────────────────┘
18:19:58 | 200 | 0s | 80.140.155.98 | GET | /
18:19:59 | 200 | 0s | 80.140.155.98 | GET | /
18:20:00 | 200 | 0s | 80.140.155.98 | GET | /
18:20:00 | 200 | 0s | 80.140.155.98 | GET | /
18:20:00 | 200 | 0s | 80.140.155.98 | GET | /
18:20:00 | 200 | 0s | 80.140.155.98 | GET | /
18:20:01 | 200 | 0s | 80.140.155.98 | GET | /
18:20:01 | 200 | 0s | 80.140.155.98 | GET | /
18:20:01 | 200 | 0s | 80.140.155.98 | GET | /
So I think 0s is really meaningless, as it could be 499ms, 15μs or even 1ns and everything inbetween. I hope there already is a way to configure it, to do what I want and I just missed it in the documentation. If not, kindly see this as a feature request :)
Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my questions prior to opening this one.
- I understand that improperly formatted questions may be closed without explanation.
Reactions are currently unavailable