improving logging (#5)

* small refactoring of error messages

* (very) small refactoring of structs instantiation

* improving logging with debug messages

* using INFO level as default + changing previous debug message to info message
This commit is contained in:
Julien Neuhart
2018-05-04 17:43:19 +02:00
committed by GitHub
parent 810d35ffbe
commit 2871fb1ffe
30 changed files with 1275 additions and 61 deletions

View File

@@ -12,6 +12,7 @@ import (
ghttp "github.com/thecodingmachine/gotenberg/app/http"
"github.com/thecodingmachine/gotenberg/app/logger"
"github.com/dustin/go-humanize"
"github.com/justinas/alice"
)
@@ -23,8 +24,10 @@ func GetHandlersChain() http.Handler {
type requestHasNoContentError struct{}
const requestHasNoContentErrorMessage = "request has not content"
func (e *requestHasNoContentError) Error() string {
return "Request has not content"
return requestHasNoContentErrorMessage
}
// enforeContentLengthHandler checks if the request has content.
@@ -120,6 +123,8 @@ func serveHandler(w http.ResponseWriter, r *http.Request) {
return
}
logger.Debugf("serving result file %s...", path)
done := make(chan error, 1)
go func() {
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", resultFileInfo.Name()))
@@ -136,6 +141,7 @@ func serveHandler(w http.ResponseWriter, r *http.Request) {
logger.Error(err)
}
logger.Infof("result file %s (%s) sent", path, humanize.Bytes(uint64(resultFileInfo.Size())))
cleanup(r)
}
@@ -143,11 +149,11 @@ func serveHandler(w http.ResponseWriter, r *http.Request) {
func cleanup(r *http.Request) {
c, err := context.GetConverter(r)
if err != nil {
logger.Warn(err.Error())
logger.Error(err)
return
}
if err := c.Clear(); err != nil {
logger.Warn(err.Error())
logger.Error(err)
}
}