Initial commit including .env
This commit is contained in:
41
middlewares/logger.go
Normal file
41
middlewares/logger.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"doormile/utils"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func ZapLogger() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
start := time.Now()
|
||||
|
||||
err := c.Next()
|
||||
|
||||
latency := time.Since(start)
|
||||
status := c.Response().StatusCode()
|
||||
method := c.Method()
|
||||
path := c.Path()
|
||||
|
||||
if err != nil {
|
||||
utils.Error("API request error",
|
||||
"method", method,
|
||||
"path", path,
|
||||
"status", status,
|
||||
"latency", latency,
|
||||
"error", err.Error(),
|
||||
)
|
||||
} else {
|
||||
utils.Info("API request success",
|
||||
"method", method,
|
||||
"path", path,
|
||||
"status", status,
|
||||
"latency", latency,
|
||||
)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user