aboutsummaryrefslogtreecommitdiff
path: root/api/logger.go
diff options
context:
space:
mode:
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}