aboutsummaryrefslogtreecommitdiff
path: root/api/logger.go
blob: 7057a3046b0dcfe2a8d6063fa80f4640630a1ec3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
		}
	}
}