[MM-31360] downgrade error logs which doesn't break the flow (#16612)
* downgrade error logs which doesn't break the flow * reflect revivew comments
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c1dd23a3c8
Коммит
f9c0c1072f
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
type Context struct {
|
||||
App app.AppIface
|
||||
Log *mlog.Logger
|
||||
Logger *mlog.Logger
|
||||
Params *Params
|
||||
Err *model.AppError
|
||||
siteURLHeader string
|
||||
@@ -68,7 +68,7 @@ func (c *Context) LogAudit(extraInfo string) {
|
||||
audit := &model.Audit{UserId: c.App.Session().UserId, IpAddress: c.App.IpAddress(), Action: c.App.Path(), ExtraInfo: extraInfo, SessionId: c.App.Session().Id}
|
||||
if err := c.App.Srv().Store.Audit().Save(audit); err != nil {
|
||||
appErr := model.NewAppError("LogAudit", "app.audit.save.saving.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.LogError(appErr)
|
||||
c.LogErrorByCode(appErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,42 +81,23 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
|
||||
audit := &model.Audit{UserId: userId, IpAddress: c.App.IpAddress(), Action: c.App.Path(), ExtraInfo: extraInfo, SessionId: c.App.Session().Id}
|
||||
if err := c.App.Srv().Store.Audit().Save(audit); err != nil {
|
||||
appErr := model.NewAppError("LogAuditWithUserId", "app.audit.save.saving.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.LogError(appErr)
|
||||
c.LogErrorByCode(appErr)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) LogError(err *model.AppError) {
|
||||
// Filter out 404s, endless reconnects and browser compatibility errors
|
||||
if err.StatusCode == http.StatusNotFound ||
|
||||
(c.App.Path() == "/api/v3/users/websocket" && err.StatusCode == http.StatusUnauthorized) ||
|
||||
err.Id == "web.check_browser_compatibility.app_error" {
|
||||
c.LogDebug(err)
|
||||
} else {
|
||||
c.Log.Error(
|
||||
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) LogErrorByCode(err *model.AppError) {
|
||||
code := err.StatusCode
|
||||
var level mlog.LogLevel
|
||||
switch {
|
||||
case (code >= http.StatusBadRequest && code < http.StatusInternalServerError) ||
|
||||
err.Id == "web.check_browser_compatibility.app_error":
|
||||
level = mlog.LvlDebug
|
||||
case code == http.StatusNotImplemented:
|
||||
level = mlog.LvlInfo
|
||||
default:
|
||||
level = mlog.LvlError
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) LogInfo(err *model.AppError) {
|
||||
// Filter out 401s
|
||||
if err.StatusCode == http.StatusUnauthorized {
|
||||
c.LogDebug(err)
|
||||
} else {
|
||||
c.Log.Info(
|
||||
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) {
|
||||
c.Log.Debug(
|
||||
c.Logger.Log(level,
|
||||
err.SystemMessage(utils.TDefault),
|
||||
mlog.String("err_where", err.Where),
|
||||
mlog.Int("http_code", err.StatusCode),
|
||||
|
||||
@@ -115,7 +115,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c.App.SetAcceptLanguage(r.Header.Get("Accept-Language"))
|
||||
c.App.SetPath(r.URL.Path)
|
||||
c.Params = ParamsFromRequest(r)
|
||||
c.Log = c.App.Log()
|
||||
c.Logger = c.App.Log()
|
||||
|
||||
if *c.App.Config().ServiceSettings.EnableOpenTracing {
|
||||
span, ctx := tracing.StartRootSpanByContext(context.Background(), "web:ServeHTTP")
|
||||
@@ -191,7 +191,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if token != "" && tokenLocation != app.TokenLocationCloudHeader {
|
||||
session, err := c.App.GetSession(token)
|
||||
if err != nil {
|
||||
c.Log.Info("Invalid session", mlog.Err(err))
|
||||
c.Logger.Info("Invalid session", mlog.Err(err))
|
||||
if err.StatusCode == http.StatusInternalServerError {
|
||||
c.Err = err
|
||||
} else if h.RequireSession {
|
||||
@@ -214,14 +214,14 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// Check to see if this provided token matches our CWS Token
|
||||
session, err := c.App.GetCloudSession(token)
|
||||
if err != nil {
|
||||
c.Log.Warn("Invalid CWS token", mlog.Err(err))
|
||||
c.Logger.Warn("Invalid CWS token", mlog.Err(err))
|
||||
c.Err = err
|
||||
} else {
|
||||
c.App.SetSession(session)
|
||||
}
|
||||
}
|
||||
|
||||
c.Log = c.App.Log().With(
|
||||
c.Logger = c.App.Log().With(
|
||||
mlog.String("path", c.App.Path()),
|
||||
mlog.String("request_id", c.App.RequestId()),
|
||||
mlog.String("ip_addr", c.App.IpAddress()),
|
||||
@@ -264,20 +264,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if c.Err != nil {
|
||||
c.Err.Translate(c.App.T)
|
||||
c.Err.RequestId = c.App.RequestId()
|
||||
|
||||
if c.Err.Id == "api.context.session_expired.app_error" {
|
||||
c.LogInfo(c.Err)
|
||||
} else {
|
||||
code := c.Err.StatusCode
|
||||
switch {
|
||||
case code >= http.StatusBadRequest && code < http.StatusInternalServerError:
|
||||
c.LogDebug(c.Err)
|
||||
case code == http.StatusNotImplemented:
|
||||
c.LogInfo(c.Err)
|
||||
default:
|
||||
c.LogError(c.Err)
|
||||
}
|
||||
}
|
||||
c.LogErrorByCode(c.Err)
|
||||
|
||||
c.Err.Where = r.URL.Path
|
||||
|
||||
@@ -350,9 +337,9 @@ func (h *Handler) checkCSRFToken(c *Context, r *http.Request, token string, toke
|
||||
}
|
||||
|
||||
if *c.App.Config().ServiceSettings.ExperimentalStrictCSRFEnforcement {
|
||||
c.Log.Warn(csrfErrorMessage, fields...)
|
||||
c.Logger.Warn(csrfErrorMessage, fields...)
|
||||
} else {
|
||||
c.Log.Debug(csrfErrorMessage, fields...)
|
||||
c.Logger.Debug(csrfErrorMessage, fields...)
|
||||
csrfCheckPassed = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,8 +451,8 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
tokenLocation := app.TokenLocationCookie
|
||||
|
||||
c := &Context{
|
||||
App: th.App,
|
||||
Log: th.App.Log(),
|
||||
App: th.App,
|
||||
Logger: th.App.Log(),
|
||||
}
|
||||
r, _ := http.NewRequest(http.MethodPost, "", nil)
|
||||
r.Header.Set(model.HEADER_REQUESTED_WITH, model.HEADER_REQUESTED_WITH_XML)
|
||||
@@ -500,8 +500,8 @@ func TestCheckCSRFToken(t *testing.T) {
|
||||
tokenLocation := app.TokenLocationCookie
|
||||
|
||||
c := &Context{
|
||||
App: th.App,
|
||||
Log: th.App.Log(),
|
||||
App: th.App,
|
||||
Logger: th.App.Log(),
|
||||
}
|
||||
r, _ := http.NewRequest(http.MethodPost, "", nil)
|
||||
r.Header.Set(model.HEADER_REQUESTED_WITH, model.HEADER_REQUESTED_WITH_XML)
|
||||
|
||||
@@ -280,7 +280,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err != nil {
|
||||
err.Translate(c.App.T)
|
||||
mlog.Error(err.Error())
|
||||
c.LogErrorByCode(err)
|
||||
if action == model.OAUTH_ACTION_MOBILE {
|
||||
w.Write([]byte(err.ToJson()))
|
||||
} else {
|
||||
@@ -292,7 +292,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.App.CompleteOAuth(service, body, teamId, props, tokenUser)
|
||||
if err != nil {
|
||||
err.Translate(c.App.T)
|
||||
mlog.Error(err.Error())
|
||||
c.LogErrorByCode(err)
|
||||
if action == model.OAUTH_ACTION_MOBILE {
|
||||
w.Write([]byte(err.ToJson()))
|
||||
} else {
|
||||
@@ -309,7 +309,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
isMobile, parseErr := strconv.ParseBool(props[model.USER_AUTH_SERVICE_IS_MOBILE])
|
||||
if parseErr != nil {
|
||||
mlog.Error("Error parsing boolean property from props", mlog.Err(parseErr))
|
||||
mlog.Debug("Error parsing boolean property from props", mlog.Err(parseErr))
|
||||
}
|
||||
err = c.App.DoLogin(w, r, user, "", isMobile, false, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -119,7 +119,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
case model.OAUTH_ACTION_SIGNUP:
|
||||
if teamId := relayProps["team_id"]; teamId != "" {
|
||||
if err = c.App.AddUserToTeamByTeamId(teamId, user); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
c.LogErrorByCode(err)
|
||||
break
|
||||
}
|
||||
c.App.AddDirectChannels(teamId, user)
|
||||
@@ -135,7 +135,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAuditWithUserId(user.Id, "Revoked all sessions for user")
|
||||
c.App.Srv().Go(func() {
|
||||
if err = c.App.Srv().EmailService.SendSignInChangeEmail(user.Email, strings.Title(model.USER_AUTH_SERVICE_SAML)+" SSO", user.Locale, c.App.GetSiteURL()); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
c.LogErrorByCode(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
isMobile, parseErr := strconv.ParseBool(relayProps[model.USER_AUTH_SERVICE_IS_MOBILE])
|
||||
if parseErr != nil {
|
||||
mlog.Error("Error parsing boolean property from relay props", mlog.Err(parseErr))
|
||||
mlog.Warn("Error parsing boolean property from relay props", mlog.Err(parseErr))
|
||||
}
|
||||
err = c.App.DoLogin(w, r, user, "", isMobile, false, true)
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user