feat: add configurable loglevel
This commit is contained in:
+1
-1
@@ -29,7 +29,7 @@ func KickoffApi(logger *slog.Logger, env utility.Environment, db *gorm.DB) {
|
||||
// r := gin.Default()
|
||||
// JSON logger: https://gin-gonic.com/en/docs/logging/structured-logging/
|
||||
r := gin.New()
|
||||
r.Use(slogMiddleware(logger))
|
||||
r.Use(slogGinMiddleware(logger))
|
||||
r.Use(gin.Recovery())
|
||||
|
||||
api := r.Group("/api")
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func slogMiddleware(logger *slog.Logger) gin.HandlerFunc {
|
||||
func slogGinMiddleware(logger *slog.Logger) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
path := c.Request.URL.Path
|
||||
@@ -15,7 +15,7 @@ func slogMiddleware(logger *slog.Logger) gin.HandlerFunc {
|
||||
|
||||
c.Next()
|
||||
|
||||
logger.Info("request",
|
||||
logger.Debug("request",
|
||||
slog.String("method", c.Request.Method),
|
||||
slog.String("path", path),
|
||||
slog.String("query", query),
|
||||
|
||||
@@ -72,6 +72,7 @@ func spawnFileRoutes(file *gin.RouterGroup, env utility.Environment, db *gorm.DB
|
||||
return
|
||||
}
|
||||
|
||||
slog.Info("saved file to local filesystem and database")
|
||||
c.JSON(http.StatusCreated, RespObj{
|
||||
Msg: "file has succesfully been uploaded",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user