aboutsummaryrefslogblamecommitdiff
path: root/api/logger.go
blob: 7057a3046b0dcfe2a8d6063fa80f4640630a1ec3 (plain) (tree)


























                                                                  
package api

import (
	"github.com/gin-gonic/gin"
	"github.com/jloup/utils"
)

var log = utils.StandardL().WithField("module", "api")

func Logger() gin.HandlerFunc {
	return func(c *gin.Context) {
		path := c.Request.URL.Path
		rawQuery := c.Request.URL.RawQuery

		c.Next()

		for _, err := range c.Errors {
			l := log.WithField("path", path)

			if rawQuery != "" {
				l = l.WithField("query", rawQuery)
			}

			l.Errorf("%s", err.Err)
		}
	}
}