New logger for the Traefik logs
This commit is contained in:
parent
27c02b5a56
commit
56f7515ecd
297 changed files with 2337 additions and 1934 deletions
|
@ -6,8 +6,8 @@ import (
|
|||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
)
|
||||
|
||||
// Failover is an http.Handler that can forward requests to the fallback handler
|
||||
|
@ -90,11 +90,11 @@ func (f *Failover) SetHandlerStatus(ctx context.Context, up bool) {
|
|||
|
||||
if up == f.handlerStatus {
|
||||
// We're still with the same status, no need to propagate.
|
||||
log.FromContext(ctx).Debugf("Still %s, no need to propagate", status)
|
||||
log.Ctx(ctx).Debug().Msgf("Still %s, no need to propagate", status)
|
||||
return
|
||||
}
|
||||
|
||||
log.FromContext(ctx).Debugf("Propagating new %s status", status)
|
||||
log.Ctx(ctx).Debug().Msgf("Propagating new %s status", status)
|
||||
f.handlerStatus = up
|
||||
|
||||
for _, fn := range f.updaters {
|
||||
|
@ -125,11 +125,11 @@ func (f *Failover) SetFallbackHandlerStatus(ctx context.Context, up bool) {
|
|||
|
||||
if up == f.fallbackStatus {
|
||||
// We're still with the same status, no need to propagate.
|
||||
log.FromContext(ctx).Debugf("Still %s, no need to propagate", status)
|
||||
log.Ctx(ctx).Debug().Msgf("Still %s, no need to propagate", status)
|
||||
return
|
||||
}
|
||||
|
||||
log.FromContext(ctx).Debugf("Propagating new %s status", status)
|
||||
log.Ctx(ctx).Debug().Msgf("Propagating new %s status", status)
|
||||
f.fallbackStatus = up
|
||||
|
||||
for _, fn := range f.updaters {
|
||||
|
|
|
@ -11,9 +11,9 @@ import (
|
|||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/healthcheck"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/middlewares/accesslog"
|
||||
"github.com/traefik/traefik/v2/pkg/safe"
|
||||
)
|
||||
|
@ -82,18 +82,18 @@ func (m *Mirroring) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
logger := log.FromContext(req.Context())
|
||||
logger := log.Ctx(req.Context())
|
||||
rr, bytesRead, err := newReusableRequest(req, m.maxBodySize)
|
||||
if err != nil && !errors.Is(err, errBodyTooLarge) {
|
||||
http.Error(rw, http.StatusText(http.StatusInternalServerError)+
|
||||
fmt.Sprintf("error creating reusable request: %v", err), http.StatusInternalServerError)
|
||||
http.Error(rw, fmt.Sprintf("%s: creating reusable request: %v",
|
||||
http.StatusText(http.StatusInternalServerError), err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if errors.Is(err, errBodyTooLarge) {
|
||||
req.Body = io.NopCloser(io.MultiReader(bytes.NewReader(bytesRead), req.Body))
|
||||
m.handler.ServeHTTP(rw, req)
|
||||
logger.Debug("no mirroring, request body larger than allowed size")
|
||||
logger.Debug().Msg("No mirroring, request body larger than allowed size")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ func (m *Mirroring) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
select {
|
||||
case <-req.Context().Done():
|
||||
// No mirroring if request has been canceled during main handler ServeHTTP
|
||||
logger.Warn("no mirroring, request has been canceled during main handler ServeHTTP")
|
||||
logger.Warn().Msg("No mirroring, request has been canceled during main handler ServeHTTP")
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ func (b blackHoleResponseWriter) Write(data []byte) (int, error) {
|
|||
return len(data), nil
|
||||
}
|
||||
|
||||
func (b blackHoleResponseWriter) WriteHeader(statusCode int) {}
|
||||
func (b blackHoleResponseWriter) WriteHeader(_ int) {}
|
||||
|
||||
type contextStopPropagation struct {
|
||||
context.Context
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
)
|
||||
|
||||
type namedHandler struct {
|
||||
|
@ -105,7 +105,9 @@ func (b *Balancer) SetStatus(ctx context.Context, childName string, up bool) {
|
|||
if up {
|
||||
status = "UP"
|
||||
}
|
||||
log.FromContext(ctx).Debugf("Setting status of %s to %v", childName, status)
|
||||
|
||||
log.Ctx(ctx).Debug().Msgf("Setting status of %s to %v", childName, status)
|
||||
|
||||
if up {
|
||||
b.status[childName] = struct{}{}
|
||||
} else {
|
||||
|
@ -121,12 +123,12 @@ func (b *Balancer) SetStatus(ctx context.Context, childName string, up bool) {
|
|||
// No Status Change
|
||||
if upBefore == upAfter {
|
||||
// We're still with the same status, no need to propagate
|
||||
log.FromContext(ctx).Debugf("Still %s, no need to propagate", status)
|
||||
log.Ctx(ctx).Debug().Msgf("Still %s, no need to propagate", status)
|
||||
return
|
||||
}
|
||||
|
||||
// Status Change
|
||||
log.FromContext(ctx).Debugf("Propagating new %s status", status)
|
||||
log.Ctx(ctx).Debug().Msgf("Propagating new %s status", status)
|
||||
for _, fn := range b.updaters {
|
||||
fn(upAfter)
|
||||
}
|
||||
|
@ -168,7 +170,7 @@ func (b *Balancer) nextServer() (*namedHandler, error) {
|
|||
}
|
||||
}
|
||||
|
||||
log.WithoutContext().Debugf("Service selected by WRR: %s", handler.name)
|
||||
log.Debug().Msgf("Service selected by WRR: %s", handler.name)
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
|
@ -177,7 +179,7 @@ func (b *Balancer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
cookie, err := req.Cookie(b.stickyCookie.name)
|
||||
|
||||
if err != nil && !errors.Is(err, http.ErrNoCookie) {
|
||||
log.WithoutContext().Warnf("Error while reading cookie: %v", err)
|
||||
log.Warn().Err(err).Msg("Error while reading cookie")
|
||||
}
|
||||
|
||||
if err == nil && cookie != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue