When a request completes ensure only one log line is printed which
includes the http response. When debugging non-successful registry requests this will place the error details and http status fields in the same log line giving easier visibility to what error occured in the request. Signed-off-by: Richard Scothern <richard.scothern@gmail.com>
This commit is contained in:
parent
01e6dde2fd
commit
54f7e5d54b
1 changed files with 8 additions and 4 deletions
|
@ -343,8 +343,12 @@ func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// Instantiate an http context here so we can track the error codes
|
// Instantiate an http context here so we can track the error codes
|
||||||
// returned by the request router.
|
// returned by the request router.
|
||||||
ctx := defaultContextManager.context(app, w, r)
|
ctx := defaultContextManager.context(app, w, r)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
status, ok := ctx.Value("http.response.status").(int)
|
||||||
|
if ok && status >= 200 && status <= 399 {
|
||||||
ctxu.GetResponseLogger(ctx).Infof("response completed")
|
ctxu.GetResponseLogger(ctx).Infof("response completed")
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
defer defaultContextManager.release(ctx)
|
defer defaultContextManager.release(ctx)
|
||||||
|
|
||||||
|
@ -424,11 +428,11 @@ func (app *App) dispatcher(dispatch dispatchFunc) http.Handler {
|
||||||
// own errors if they need different behavior (such as range errors
|
// own errors if they need different behavior (such as range errors
|
||||||
// for layer upload).
|
// for layer upload).
|
||||||
if context.Errors.Len() > 0 {
|
if context.Errors.Len() > 0 {
|
||||||
app.logError(context, context.Errors)
|
|
||||||
|
|
||||||
if err := errcode.ServeJSON(w, context.Errors); err != nil {
|
if err := errcode.ServeJSON(w, context.Errors); err != nil {
|
||||||
ctxu.GetLogger(context).Errorf("error serving error json: %v (from %v)", err, context.Errors)
|
ctxu.GetLogger(context).Errorf("error serving error json: %v (from %v)", err, context.Errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.logError(context, context.Errors)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -457,7 +461,7 @@ func (app *App) logError(context context.Context, errors errcode.Errors) {
|
||||||
"err.code",
|
"err.code",
|
||||||
"err.message",
|
"err.message",
|
||||||
"err.detail"))
|
"err.detail"))
|
||||||
ctxu.GetLogger(c).Errorf("An error occured")
|
ctxu.GetResponseLogger(c).Errorf("response completed with error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue