From 7417a8317b77f6f5ebd4ee1ed5f0bf02c1ef3211 Mon Sep 17 00:00:00 2001 From: Riyaz Faizullabhoy Date: Wed, 22 Jun 2016 17:34:30 -0700 Subject: [PATCH] bottleneck http error logging in root handler Signed-off-by: Riyaz Faizullabhoy --- utils/http.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/http.go b/utils/http.go index 3641da0477..03a6cf9bab 100644 --- a/utils/http.go +++ b/utils/http.go @@ -79,6 +79,16 @@ func (root *rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx = authCtx } if err := root.handler(ctx, w, r); err != nil { + if httpErr, ok := err.(errcode.ErrorCoder); ok { + // info level logging for non-5XX http errors + httpErrCode := httpErr.ErrorCode().Descriptor().HTTPStatusCode + if (httpErrCode < http.StatusOK || httpErrCode >= http.StatusMultipleChoices) && httpErrCode < http.StatusInternalServerError { + logrus.Info(httpErr) + } else if httpErrCode >= http.StatusInternalServerError { + // error level logging for 5XX http errors + logrus.Error(httpErr) + } + } e := errcode.ServeJSON(w, err) if e != nil { logrus.Error(e)