New logger for the Traefik logs
This commit is contained in:
parent
27c02b5a56
commit
56f7515ecd
297 changed files with 2337 additions and 1934 deletions
|
@ -4,8 +4,9 @@ import (
|
|||
"sort"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Status of the router/service.
|
||||
|
@ -116,8 +117,6 @@ func (c *Configuration) PopulateUsedBy() {
|
|||
return
|
||||
}
|
||||
|
||||
logger := log.WithoutContext()
|
||||
|
||||
for routerName, routerInfo := range c.Routers {
|
||||
// lazily initialize Status in case caller forgot to do it
|
||||
if routerInfo.Status == "" {
|
||||
|
@ -126,7 +125,7 @@ func (c *Configuration) PopulateUsedBy() {
|
|||
|
||||
providerName := getProviderName(routerName)
|
||||
if providerName == "" {
|
||||
logger.WithField(log.RouterName, routerName).Error("router name is not fully qualified")
|
||||
log.Error().Str(logs.RouterName, routerName).Msg("Router name is not fully qualified")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -171,7 +170,7 @@ func (c *Configuration) PopulateUsedBy() {
|
|||
|
||||
providerName := getProviderName(routerName)
|
||||
if providerName == "" {
|
||||
logger.WithField(log.RouterName, routerName).Error("tcp router name is not fully qualified")
|
||||
log.Error().Str(logs.RouterName, routerName).Msg("TCP router name is not fully qualified")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -208,7 +207,7 @@ func (c *Configuration) PopulateUsedBy() {
|
|||
|
||||
providerName := getProviderName(routerName)
|
||||
if providerName == "" {
|
||||
logger.WithField(log.RouterName, routerName).Error("udp router name is not fully qualified")
|
||||
log.Error().Str(logs.RouterName, routerName).Msg("UDP router name is not fully qualified")
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,9 @@ import (
|
|||
"sort"
|
||||
"sync"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// GetRoutersByEntryPoints returns all the http routers by entry points name and routers name.
|
||||
|
@ -19,14 +20,14 @@ func (c *Configuration) GetRoutersByEntryPoints(ctx context.Context, entryPoints
|
|||
continue
|
||||
}
|
||||
|
||||
logger := log.FromContext(log.With(ctx, log.Str(log.RouterName, rtName)))
|
||||
logger := log.Ctx(ctx).With().Str(logs.RouterName, rtName).Logger()
|
||||
|
||||
entryPointsCount := 0
|
||||
for _, entryPointName := range rt.EntryPoints {
|
||||
if !contains(entryPoints, entryPointName) {
|
||||
rt.AddError(fmt.Errorf("entryPoint %q doesn't exist", entryPointName), false)
|
||||
logger.WithField(log.EntryPointName, entryPointName).
|
||||
Errorf("entryPoint %q doesn't exist", entryPointName)
|
||||
logger.Error().Str(logs.EntryPointName, entryPointName).
|
||||
Msg("EntryPoint doesn't exist")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -42,7 +43,7 @@ func (c *Configuration) GetRoutersByEntryPoints(ctx context.Context, entryPoints
|
|||
|
||||
if entryPointsCount == 0 {
|
||||
rt.AddError(fmt.Errorf("no valid entryPoint for this router"), true)
|
||||
logger.Error("no valid entryPoint for this router")
|
||||
logger.Error().Msg("No valid entryPoint for this router")
|
||||
}
|
||||
|
||||
rt.Using = unique(rt.Using)
|
||||
|
|
|
@ -4,8 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// GetTCPRoutersByEntryPoints returns all the tcp routers by entry points name and routers name.
|
||||
|
@ -13,14 +14,14 @@ func (c *Configuration) GetTCPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
entryPointsRouters := make(map[string]map[string]*TCPRouterInfo)
|
||||
|
||||
for rtName, rt := range c.TCPRouters {
|
||||
logger := log.FromContext(log.With(ctx, log.Str(log.RouterName, rtName)))
|
||||
logger := log.Ctx(ctx).With().Str(logs.RouterName, rtName).Logger()
|
||||
|
||||
entryPointsCount := 0
|
||||
for _, entryPointName := range rt.EntryPoints {
|
||||
if !contains(entryPoints, entryPointName) {
|
||||
rt.AddError(fmt.Errorf("entryPoint %q doesn't exist", entryPointName), false)
|
||||
logger.WithField(log.EntryPointName, entryPointName).
|
||||
Errorf("entryPoint %q doesn't exist", entryPointName)
|
||||
logger.Error().Str(logs.EntryPointName, entryPointName).
|
||||
Msg("EntryPoint doesn't exist")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -36,7 +37,7 @@ func (c *Configuration) GetTCPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
|
||||
if entryPointsCount == 0 {
|
||||
rt.AddError(fmt.Errorf("no valid entryPoint for this router"), true)
|
||||
logger.Error("no valid entryPoint for this router")
|
||||
logger.Error().Msg("No valid entryPoint for this router")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// GetUDPRoutersByEntryPoints returns all the UDP routers by entry points name and routers name.
|
||||
|
@ -13,11 +14,11 @@ func (c *Configuration) GetUDPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
entryPointsRouters := make(map[string]map[string]*UDPRouterInfo)
|
||||
|
||||
for rtName, rt := range c.UDPRouters {
|
||||
logger := log.FromContext(log.With(ctx, log.Str(log.RouterName, rtName)))
|
||||
logger := log.Ctx(ctx).With().Str(logs.RouterName, rtName).Logger()
|
||||
|
||||
eps := rt.EntryPoints
|
||||
if len(eps) == 0 {
|
||||
logger.Debugf("No entryPoint defined for this router, using the default one(s) instead: %+v", entryPoints)
|
||||
logger.Debug().Msgf("No entryPoint defined for this router, using the default one(s) instead: %+v", entryPoints)
|
||||
eps = entryPoints
|
||||
}
|
||||
|
||||
|
@ -25,8 +26,8 @@ func (c *Configuration) GetUDPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
for _, entryPointName := range eps {
|
||||
if !contains(entryPoints, entryPointName) {
|
||||
rt.AddError(fmt.Errorf("entryPoint %q doesn't exist", entryPointName), false)
|
||||
logger.WithField(log.EntryPointName, entryPointName).
|
||||
Errorf("entryPoint %q doesn't exist", entryPointName)
|
||||
logger.Error().Str(logs.EntryPointName, entryPointName).
|
||||
Msg("EntryPoint doesn't exist")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -42,7 +43,7 @@ func (c *Configuration) GetUDPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
|
||||
if entryPointsCount == 0 {
|
||||
rt.AddError(fmt.Errorf("no valid entryPoint for this router"), true)
|
||||
logger.Error("no valid entryPoint for this router")
|
||||
logger.Error().Msg("No valid entryPoint for this router")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ package static
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/logs"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/hub"
|
||||
)
|
||||
|
||||
|
@ -18,7 +19,9 @@ func (c *Configuration) initHubProvider() error {
|
|||
ep.SetDefaults()
|
||||
ep.Address = ":9901"
|
||||
c.EntryPoints[hub.TunnelEntrypoint] = &ep
|
||||
log.WithoutContext().Infof("The entryPoint %q is created on port 9901 to allow exposition of services.", hub.TunnelEntrypoint)
|
||||
|
||||
log.Info().Str(logs.EntryPointName, hub.TunnelEntrypoint).
|
||||
Msg("The entryPoint is created on port 9901 to allow exposition of services.")
|
||||
}
|
||||
|
||||
if c.Hub.TLS == nil {
|
||||
|
@ -34,7 +37,7 @@ func (c *Configuration) initHubProvider() error {
|
|||
}
|
||||
|
||||
if c.Hub.TLS.Insecure {
|
||||
log.WithoutContext().Warn("Hub is in `insecure` mode. Do not run in production with this setup.")
|
||||
log.Warn().Msg("Hub is in `insecure` mode. Do not run in production with this setup.")
|
||||
}
|
||||
|
||||
if _, ok := c.EntryPoints[hub.APIEntrypoint]; !ok {
|
||||
|
@ -42,7 +45,9 @@ func (c *Configuration) initHubProvider() error {
|
|||
ep.SetDefaults()
|
||||
ep.Address = ":9900"
|
||||
c.EntryPoints[hub.APIEntrypoint] = &ep
|
||||
log.WithoutContext().Infof("The entryPoint %q is created on port 9900 to allow Traefik to communicate with the Hub Agent for Traefik.", hub.APIEntrypoint)
|
||||
|
||||
log.Info().Str(logs.EntryPointName, hub.APIEntrypoint).
|
||||
Msg("The entryPoint is created on port 9900 to allow Traefik to communicate with the Hub Agent for Traefik.")
|
||||
}
|
||||
|
||||
c.EntryPoints[hub.APIEntrypoint].HTTP.TLS = &TLSConfig{
|
||||
|
|
|
@ -2,14 +2,14 @@ package static
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
stdlog "log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
legolog "github.com/go-acme/lego/v4/log"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
ptypes "github.com/traefik/paerser/types"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/logs"
|
||||
"github.com/traefik/traefik/v2/pkg/ping"
|
||||
acmeprovider "github.com/traefik/traefik/v2/pkg/provider/acme"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/consulcatalog"
|
||||
|
@ -242,9 +242,9 @@ func (c *Configuration) SetEffectiveConfiguration() {
|
|||
if c.Hub != nil {
|
||||
if err := c.initHubProvider(); err != nil {
|
||||
c.Hub = nil
|
||||
log.WithoutContext().Errorf("Unable to activate the Hub provider: %v", err)
|
||||
log.Error().Err(err).Msg("Unable to activate the Hub provider")
|
||||
} else {
|
||||
log.WithoutContext().Debugf("Experimental Hub provider has been activated.")
|
||||
log.Debug().Msg("Experimental Hub provider has been activated")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,14 +278,15 @@ func (c *Configuration) SetEffectiveConfiguration() {
|
|||
for epName, ep := range c.EntryPoints {
|
||||
if ep.HTTP3 != nil {
|
||||
ep.HTTP3 = nil
|
||||
log.WithoutContext().Debugf("Disabling HTTP3 configuration for entryPoint %q: HTTP3 is disabled in the experimental configuration section", epName)
|
||||
log.Debug().Str(logs.EntryPointName, epName).
|
||||
Msgf("Disabling HTTP3 configuration for entryPoint %q: HTTP3 is disabled in the experimental configuration section", epName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configure Gateway API provider
|
||||
if c.Providers.KubernetesGateway != nil {
|
||||
log.WithoutContext().Debugf("Experimental Kubernetes Gateway provider has been activated")
|
||||
log.Debug().Msg("Experimental Kubernetes Gateway provider has been activated")
|
||||
entryPoints := make(map[string]gateway.Entrypoint)
|
||||
for epName, entryPoint := range c.EntryPoints {
|
||||
entryPoints[epName] = gateway.Entrypoint{Address: entryPoint.GetAddress(), HasHTTPTLSConf: entryPoint.HTTP.TLS != nil}
|
||||
|
@ -319,7 +320,8 @@ func (c *Configuration) initACMEProvider() {
|
|||
}
|
||||
}
|
||||
|
||||
legolog.Logger = stdlog.New(log.WithoutContext().WriterLevel(logrus.DebugLevel), "legolog: ", 0)
|
||||
logger := logs.NoLevel(log.Logger, zerolog.DebugLevel).With().Str("lib", "lego").Logger()
|
||||
legolog.Logger = logs.NewLogrusWrapper(logger)
|
||||
}
|
||||
|
||||
// ValidateConfiguration validate that configuration is coherent.
|
||||
|
@ -366,15 +368,13 @@ func getSafeACMECAServer(caServerSrc string) string {
|
|||
|
||||
if strings.HasPrefix(caServerSrc, "https://acme-v01.api.letsencrypt.org") {
|
||||
caServer := strings.Replace(caServerSrc, "v01", "v02", 1)
|
||||
log.WithoutContext().
|
||||
Warnf("The CA server %[1]q refers to a v01 endpoint of the ACME API, please change to %[2]q. Fallback to %[2]q.", caServerSrc, caServer)
|
||||
log.Warn().Msgf("The CA server %[1]q refers to a v01 endpoint of the ACME API, please change to %[2]q. Fallback to %[2]q.", caServerSrc, caServer)
|
||||
return caServer
|
||||
}
|
||||
|
||||
if strings.HasPrefix(caServerSrc, "https://acme-staging.api.letsencrypt.org") {
|
||||
caServer := strings.Replace(caServerSrc, "https://acme-staging.api.letsencrypt.org", "https://acme-staging-v02.api.letsencrypt.org", 1)
|
||||
log.WithoutContext().
|
||||
Warnf("The CA server %[1]q refers to a v01 endpoint of the ACME API, please change to %[2]q. Fallback to %[2]q.", caServerSrc, caServer)
|
||||
log.Warn().Msgf("The CA server %[1]q refers to a v01 endpoint of the ACME API, please change to %[2]q. Fallback to %[2]q.", caServerSrc, caServer)
|
||||
return caServer
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue