From 7a9e5112eaaea58d55f181d3e5296e4ff839921c Mon Sep 17 00:00:00 2001 From: jloup Date: Wed, 14 Feb 2018 14:19:09 +0100 Subject: initial commit --- api/logger.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 api/logger.go (limited to 'api/logger.go') 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 @@ +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) + } + } +} -- cgit v1.2.3