Adding mlog to context. (#8882)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
260d7a0f85
Коммит
ebdceb8e52
@@ -4,7 +4,6 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -19,6 +18,7 @@ import (
|
|||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
App *app.App
|
App *app.App
|
||||||
|
Log *mlog.Logger
|
||||||
Session model.Session
|
Session model.Session
|
||||||
Params *Params
|
Params *Params
|
||||||
Err *model.AppError
|
Err *model.AppError
|
||||||
@@ -55,8 +55,12 @@ func (c *Context) LogError(err *model.AppError) {
|
|||||||
err.Id == "web.check_browser_compatibility.app_error" {
|
err.Id == "web.check_browser_compatibility.app_error" {
|
||||||
c.LogDebug(err)
|
c.LogDebug(err)
|
||||||
} else {
|
} else {
|
||||||
mlog.Error(fmt.Sprintf("%v:%v code=%v rid=%v uid=%v ip=%v %v [details: %v]", c.Path, err.Where, err.StatusCode,
|
c.Log.Error(
|
||||||
c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.TDefault), err.DetailedError), mlog.String("user_id", c.Session.UserId))
|
err.SystemMessage(utils.TDefault),
|
||||||
|
mlog.String("err_where", err.Where),
|
||||||
|
mlog.Int("http_code", err.StatusCode),
|
||||||
|
mlog.String("err_details", err.DetailedError),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,14 +69,22 @@ func (c *Context) LogInfo(err *model.AppError) {
|
|||||||
if err.StatusCode == http.StatusUnauthorized {
|
if err.StatusCode == http.StatusUnauthorized {
|
||||||
c.LogDebug(err)
|
c.LogDebug(err)
|
||||||
} else {
|
} else {
|
||||||
mlog.Info(fmt.Sprintf("%v:%v code=%v rid=%v uid=%v ip=%v %v [details: %v]", c.Path, err.Where, err.StatusCode,
|
c.Log.Info(
|
||||||
c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.TDefault), err.DetailedError), mlog.String("user_id", c.Session.UserId))
|
err.SystemMessage(utils.TDefault),
|
||||||
|
mlog.String("err_where", err.Where),
|
||||||
|
mlog.Int("http_code", err.StatusCode),
|
||||||
|
mlog.String("err_details", err.DetailedError),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) LogDebug(err *model.AppError) {
|
func (c *Context) LogDebug(err *model.AppError) {
|
||||||
mlog.Debug(fmt.Sprintf("%v:%v code=%v rid=%v uid=%v ip=%v %v [details: %v]", c.Path, err.Where, err.StatusCode,
|
c.Log.Debug(
|
||||||
c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.TDefault), err.DetailedError), mlog.String("user_id", c.Session.UserId))
|
err.SystemMessage(utils.TDefault),
|
||||||
|
mlog.String("err_where", err.Where),
|
||||||
|
mlog.Int("http_code", err.StatusCode),
|
||||||
|
mlog.String("err_details", err.DetailedError),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) IsSystemAdmin() bool {
|
func (c *Context) IsSystemAdmin() bool {
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
c.RequestId = model.NewId()
|
c.RequestId = model.NewId()
|
||||||
c.IpAddress = utils.GetIpAddress(r)
|
c.IpAddress = utils.GetIpAddress(r)
|
||||||
c.Params = ParamsFromRequest(r)
|
c.Params = ParamsFromRequest(r)
|
||||||
|
c.Path = r.URL.Path
|
||||||
|
c.Log = c.App.Log
|
||||||
|
|
||||||
token, tokenLocation := app.ParseAuthTokenFromRequest(r)
|
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)
|
session, err := c.App.GetSession(token)
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
if err.StatusCode == http.StatusInternalServerError {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
} else if h.RequireSession {
|
} 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 {
|
if c.Err == nil && h.RequireSession {
|
||||||
c.SessionRequired()
|
c.SessionRequired()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user