32 lines
486 B
Go
32 lines
486 B
Go
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// Logger 日志中间件
|
|
func Logger() fiber.Handler {
|
|
return func(c fiber.Ctx) error {
|
|
start := time.Now()
|
|
err := c.Next()
|
|
latency := time.Since(start)
|
|
|
|
fmt.Printf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
|
|
c.IP(),
|
|
time.Now().Format(time.RFC1123),
|
|
c.Method(),
|
|
c.Path(),
|
|
c.Protocol(),
|
|
c.Response().StatusCode(),
|
|
latency,
|
|
c.Get("User-Agent"),
|
|
"",
|
|
)
|
|
|
|
return err
|
|
}
|
|
}
|