summaryrefslogtreecommitdiffstats
path: root/web/handlers.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-06-01 13:07:56 -0700
committerGitHub <noreply@github.com>2018-06-01 13:07:56 -0700
commitebdceb8e529810cd89599b8fbfda0157a659f3b5 (patch)
treef77f1bf8131006790b1792000bca1e06e7cd2211 /web/handlers.go
parent260d7a0f850a6f772b14b011022f1f65213a08a1 (diff)
downloadchat-ebdceb8e529810cd89599b8fbfda0157a659f3b5.tar.gz
chat-ebdceb8e529810cd89599b8fbfda0157a659f3b5.tar.bz2
chat-ebdceb8e529810cd89599b8fbfda0157a659f3b5.zip
Adding mlog to context. (#8882)
Diffstat (limited to 'web/handlers.go')
-rw-r--r--web/handlers.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/web/handlers.go b/web/handlers.go
index e2521674a..363b05c59 100644
--- a/web/handlers.go
+++ b/web/handlers.go
@@ -55,6 +55,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.RequestId = model.NewId()
c.IpAddress = utils.GetIpAddress(r)
c.Params = ParamsFromRequest(r)
+ c.Path = r.URL.Path
+ c.Log = c.App.Log
token, tokenLocation := app.ParseAuthTokenFromRequest(r)
@@ -88,7 +90,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
session, err := c.App.GetSession(token)
if err != nil {
- mlog.Info(fmt.Sprintf("Invalid session err=%v", err.Error()))
+ c.Log.Info("Invalid session", mlog.Err(err))
if err.StatusCode == http.StatusInternalServerError {
c.Err = err
} else if h.RequireSession {
@@ -107,7 +109,13 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
- c.Path = r.URL.Path
+ c.Log = c.App.Log.With(
+ mlog.String("path", c.Path),
+ mlog.String("request_id", c.RequestId),
+ mlog.String("ip_addr", c.IpAddress),
+ mlog.String("user_id", c.Session.UserId),
+ mlog.String("method", r.Method),
+ )
if c.Err == nil && h.RequireSession {
c.SessionRequired()