Always log errors

This commit is contained in:
Justin Li 2014-07-23 01:31:22 -04:00
parent 84195deb58
commit 856568f1a8

View file

@ -17,7 +17,6 @@ import (
"github.com/chihaya/chihaya/config" "github.com/chihaya/chihaya/config"
"github.com/chihaya/chihaya/stats" "github.com/chihaya/chihaya/stats"
"github.com/chihaya/chihaya/tracker" "github.com/chihaya/chihaya/tracker"
"github.com/chihaya/chihaya/tracker/models"
) )
type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (int, error) type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (int, error)
@ -31,15 +30,13 @@ func makeHandler(handler ResponseHandler) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
start := time.Now() start := time.Now()
httpCode, err := handler(w, r, p) httpCode, err := handler(w, r, p)
stats.RecordEvent(stats.HandledRequest)
duration := time.Since(start) duration := time.Since(start)
stats.RecordTiming(stats.ResponseTime, duration)
if err != nil { if err != nil {
stats.RecordEvent(stats.ErroredRequest) stats.RecordEvent(stats.ErroredRequest)
http.Error(w, err.Error(), httpCode) http.Error(w, err.Error(), httpCode)
if glog.V(2) {
glog.Infof( glog.Errorf(
"Failed (%v:%s) %s with %s in %s", "Failed (%v:%s) %s with %s in %s",
httpCode, httpCode,
http.StatusText(httpCode), http.StatusText(httpCode),
@ -47,7 +44,6 @@ func makeHandler(handler ResponseHandler) httprouter.Handle {
err.Error(), err.Error(),
duration, duration,
) )
}
} else if glog.V(2) { } else if glog.V(2) {
glog.Infof( glog.Infof(
"Completed (%v:%s) %s in %v", "Completed (%v:%s) %s in %v",
@ -57,6 +53,9 @@ func makeHandler(handler ResponseHandler) httprouter.Handle {
duration, duration,
) )
} }
stats.RecordEvent(stats.HandledRequest)
stats.RecordTiming(stats.ResponseTime, duration)
} }
} }