This commit is contained in:
Corey Hulen
2016-06-29 04:16:20 -08:00
committed by Christopher Speller
parent 6c5a8be6bf
commit b63f61fe7d
3 changed files with 41 additions and 4 deletions

View File

@@ -283,6 +283,11 @@ func (c *Context) LogError(err *model.AppError) {
c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.T), err.DetailedError)
}
func (c *Context) LogDebug(err *model.AppError) {
l4g.Debug(utils.T("api.context.log.error"), c.Path, err.Where, err.StatusCode,
c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.T), err.DetailedError)
}
func (c *Context) UserRequired() {
if len(c.Session.UserId) == 0 {
c.Err = model.NewLocAppError("", "api.context.session_expired.app_error", nil, "UserRequired")
@@ -481,7 +486,13 @@ func Handle404(w http.ResponseWriter, r *http.Request) {
err := model.NewLocAppError("Handle404", "api.context.404.app_error", nil, "")
err.Translate(utils.T)
err.StatusCode = http.StatusNotFound
l4g.Error("%v: code=404 ip=%v", r.URL.Path, GetIpAddress(r))
// filter out old paths that are poluting the log file
if strings.Contains(r.URL.Path, "/api/v1/") {
l4g.Debug("%v: code=404 ip=%v", r.URL.Path, GetIpAddress(r))
} else {
l4g.Error("%v: code=404 ip=%v", r.URL.Path, GetIpAddress(r))
}
if IsApiCall(r) {
w.WriteHeader(err.StatusCode)

View File

@@ -6,6 +6,7 @@ package api
import (
"fmt"
"net/http"
"strings"
l4g "github.com/alecthomas/log4go"
@@ -27,11 +28,22 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
func logClient(c *Context, w http.ResponseWriter, r *http.Request) {
forceToDebug := false
if !*utils.Cfg.ServiceSettings.EnableDeveloper {
forceToDebug = true
}
m := model.MapFromJson(r.Body)
lvl := m["level"]
msg := m["message"]
// filter out javascript errors from franz that are poluting the log files
if strings.Contains(msg, "/franz") {
forceToDebug = true
}
if len(msg) > 400 {
msg = msg[0:399]
}
@@ -41,7 +53,12 @@ func logClient(c *Context, w http.ResponseWriter, r *http.Request) {
err.Message = msg
err.Id = msg
err.Where = "client"
c.LogError(err)
if forceToDebug {
c.LogDebug(err)
} else {
c.LogError(err)
}
}
ReturnStatusOK(w)