New logger for the Traefik logs
This commit is contained in:
parent
27c02b5a56
commit
56f7515ecd
297 changed files with 2337 additions and 1934 deletions
|
@ -8,8 +8,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/logs"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/tls"
|
||||
|
@ -32,8 +33,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
}
|
||||
|
||||
for _, ingressRoute := range client.GetIngressRoutes() {
|
||||
ctxRt := log.With(ctx, log.Str("ingress", ingressRoute.Name), log.Str("namespace", ingressRoute.Namespace))
|
||||
logger := log.FromContext(ctxRt)
|
||||
logger := log.Ctx(ctx).With().Str("ingress", ingressRoute.Name).Str("namespace", ingressRoute.Namespace).Logger()
|
||||
|
||||
// TODO keep the name ingressClass?
|
||||
if !shouldProcessIngress(p.IngressClass, ingressRoute.Annotations[annotationKubernetesIngressClass]) {
|
||||
|
@ -42,7 +42,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
|
||||
err := getTLSHTTP(ctx, ingressRoute, client, tlsConfigs)
|
||||
if err != nil {
|
||||
logger.Errorf("Error configuring TLS: %v", err)
|
||||
logger.Error().Err(err).Msg("Error configuring TLS")
|
||||
}
|
||||
|
||||
ingressName := ingressRoute.Name
|
||||
|
@ -59,24 +59,24 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
|
||||
for _, route := range ingressRoute.Spec.Routes {
|
||||
if route.Kind != "Rule" {
|
||||
logger.Errorf("Unsupported match kind: %s. Only \"Rule\" is supported for now.", route.Kind)
|
||||
logger.Error().Msgf("Unsupported match kind: %s. Only \"Rule\" is supported for now.", route.Kind)
|
||||
continue
|
||||
}
|
||||
|
||||
if len(route.Match) == 0 {
|
||||
logger.Errorf("Empty match rule")
|
||||
logger.Error().Msg("Empty match rule")
|
||||
continue
|
||||
}
|
||||
|
||||
serviceKey, err := makeServiceKey(route.Match, ingressName)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
|
||||
mds, err := p.makeMiddlewareKeys(ctx, ingressRoute.Namespace, route.Middlewares)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to create middleware keys: %v", err)
|
||||
logger.Error().Err(err).Msg("Failed to create middleware keys")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -92,13 +92,13 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
|
||||
errBuild := cb.buildServicesLB(ctx, ingressRoute.Namespace, spec, serviceName, conf.Services)
|
||||
if errBuild != nil {
|
||||
logger.Error(errBuild)
|
||||
logger.Error().Err(errBuild).Send()
|
||||
continue
|
||||
}
|
||||
} else if len(route.Services) == 1 {
|
||||
fullName, serversLB, err := cb.nameAndService(ctx, ingressRoute.Namespace, route.Services[0].LoadBalancerSpec)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -134,12 +134,12 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
tlsOptionsName = makeID(ns, tlsOptionsName)
|
||||
} else if len(ns) > 0 {
|
||||
logger.
|
||||
WithField("TLSOption", ingressRoute.Spec.TLS.Options.Name).
|
||||
Warnf("Namespace %q is ignored in cross-provider context", ns)
|
||||
Warn().Str("TLSOption", ingressRoute.Spec.TLS.Options.Name).
|
||||
Msgf("Namespace %q is ignored in cross-provider context", ns)
|
||||
}
|
||||
|
||||
if !isNamespaceAllowed(p.AllowCrossNamespace, ingressRoute.Namespace, ns) {
|
||||
logger.Errorf("TLSOption %s/%s is not in the IngressRoute namespace %s",
|
||||
logger.Error().Msgf("TLSOption %s/%s is not in the IngressRoute namespace %s",
|
||||
ns, ingressRoute.Spec.TLS.Options.Name, ingressRoute.Namespace)
|
||||
continue
|
||||
}
|
||||
|
@ -170,9 +170,9 @@ func (p *Provider) makeMiddlewareKeys(ctx context.Context, ingRouteNamespace str
|
|||
|
||||
if strings.Contains(name, providerNamespaceSeparator) {
|
||||
if len(mi.Namespace) > 0 {
|
||||
log.FromContext(ctx).
|
||||
WithField(log.MiddlewareName, mi.Name).
|
||||
Warnf("namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
log.Ctx(ctx).
|
||||
Warn().Str(logs.MiddlewareName, mi.Name).
|
||||
Msgf("namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
}
|
||||
|
||||
mds = append(mds, name)
|
||||
|
@ -439,7 +439,7 @@ func (c configBuilder) loadServers(parentNamespace string, svc v1alpha1.LoadBala
|
|||
// it generates and returns the configuration part for such a service,
|
||||
// so that the caller can add it to the global config map.
|
||||
func (c configBuilder) nameAndService(ctx context.Context, parentNamespace string, service v1alpha1.LoadBalancerSpec) (string, *dynamic.Service, error) {
|
||||
svcCtx := log.With(ctx, log.Str(log.ServiceName, service.Name))
|
||||
svcCtx := log.Ctx(ctx).With().Str(logs.ServiceName, service.Name).Logger().WithContext(ctx)
|
||||
|
||||
namespace := namespaceOrFallback(service, parentNamespace)
|
||||
|
||||
|
@ -488,7 +488,7 @@ func fullServiceName(ctx context.Context, namespace string, service v1alpha1.Loa
|
|||
}
|
||||
|
||||
if service.Namespace != "" {
|
||||
log.FromContext(ctx).Warnf("namespace %q is ignored in cross-provider context", service.Namespace)
|
||||
log.Ctx(ctx).Warn().Msgf("namespace %q is ignored in cross-provider context", service.Namespace)
|
||||
}
|
||||
|
||||
return provider.Normalize(name) + providerNamespaceSeparator + pName
|
||||
|
@ -507,7 +507,7 @@ func getTLSHTTP(ctx context.Context, ingressRoute *v1alpha1.IngressRoute, k8sCli
|
|||
return nil
|
||||
}
|
||||
if ingressRoute.Spec.TLS.SecretName == "" {
|
||||
log.FromContext(ctx).Debugf("No secret name provided")
|
||||
log.Ctx(ctx).Debug().Msg("No secret name provided")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue