mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
reverseproxy: Make debug log safe if error occurs
This commit is contained in:
parent
812278acd8
commit
9ee01dceac
1 changed files with 8 additions and 4 deletions
|
@ -461,20 +461,24 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia
|
|||
// point the request to this upstream
|
||||
h.directRequest(req, di)
|
||||
|
||||
// do the round-trip
|
||||
// do the round-trip; emit debug log with values we know are
|
||||
// safe, or if there is no error, emit fuller log entry
|
||||
start := time.Now()
|
||||
res, err := h.Transport.RoundTrip(req)
|
||||
duration := time.Since(start)
|
||||
h.logger.Debug("upstream roundtrip",
|
||||
logger := h.logger.With(
|
||||
zap.String("upstream", di.Upstream.String()),
|
||||
zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: req}),
|
||||
zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)),
|
||||
zap.Duration("duration", duration),
|
||||
zap.Int("status", res.StatusCode),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Debug("upstream roundtrip", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
logger.Debug("upstream roundtrip",
|
||||
zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)),
|
||||
zap.Int("status", res.StatusCode),
|
||||
)
|
||||
|
||||
// update circuit breaker on current conditions
|
||||
if di.Upstream.cb != nil {
|
||||
|
|
Loading…
Reference in a new issue