aboutsummaryrefslogtreecommitdiff
path: root/api/logger.go
diff options
context:
space:
mode:
authorjloup <jean-loup.jamet@trainline.com>2018-02-14 14:19:09 +0100
committerjloup <jean-loup.jamet@trainline.com>2018-02-14 14:19:09 +0100
commit7a9e5112eaaea58d55f181d3e5296e4ff839921c (patch)
tree968ed193f42a1fad759cc89ad2f8ad5b0091291e /api/logger.go
downloadFront-7a9e5112eaaea58d55f181d3e5296e4ff839921c.tar.gz
Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.tar.zst
Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.zip
initial commit
Diffstat (limited to 'api/logger.go')
-rw-r--r--api/logger.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/api/logger.go b/api/logger.go
new file mode 100644
index 0000000..7057a30
--- /dev/null
+++ b/api/logger.go
@@ -0,0 +1,27 @@
1package api
2
3import (
4 "github.com/gin-gonic/gin"
5 "github.com/jloup/utils"
6)
7
8var log = utils.StandardL().WithField("module", "api")
9
10func Logger() gin.HandlerFunc {
11 return func(c *gin.Context) {
12 path := c.Request.URL.Path
13 rawQuery := c.Request.URL.RawQuery
14
15 c.Next()
16
17 for _, err := range c.Errors {
18 l := log.WithField("path", path)
19
20 if rawQuery != "" {
21 l = l.WithField("query", rawQuery)
22 }
23
24 l.Errorf("%s", err.Err)
25 }
26 }
27}