slighty improvement of logging (#6)

This commit is contained in:
Julien Neuhart
2018-05-16 10:02:07 +02:00
committed by GitHub
parent 2871fb1ffe
commit faec55dd01
3 changed files with 90 additions and 17 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/justinas/alice"
"github.com/satori/go.uuid"
)
// GetHandlersChain returns the handlers chaining
@@ -40,6 +41,10 @@ func enforceContentLengthHandler(next http.Handler) http.Handler {
return
}
requestID := uuid.NewV4().String()
r = context.WithRequestID(r, requestID)
logger.Infof("identified new request (%s) with %s", humanize.Bytes(uint64(r.ContentLength)), requestID)
next.ServeHTTP(w, r)
})
}
@@ -123,7 +128,12 @@ func serveHandler(w http.ResponseWriter, r *http.Request) {
return
}
logger.Debugf("serving result file %s...", path)
requestID, err := context.GetRequestID(r)
if err != nil {
logger.Error(err)
}
logger.Debugf("serving result file %s for request %s...", path, requestID)
done := make(chan error, 1)
go func() {
@@ -139,9 +149,10 @@ func serveHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
logger.Error(err)
} else {
logger.Infof("result file %s (%s) sent for request %s", path, humanize.Bytes(uint64(resultFileInfo.Size())), requestID)
}
logger.Infof("result file %s (%s) sent", path, humanize.Bytes(uint64(resultFileInfo.Size())))
cleanup(r)
}