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,9 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/logs"
|
||||
"github.com/traefik/yaegi/interp"
|
||||
"github.com/traefik/yaegi/stdlib"
|
||||
)
|
||||
|
@ -35,12 +36,13 @@ func NewBuilder(client *Client, plugins map[string]Descriptor, localPlugins map[
|
|||
return nil, fmt.Errorf("%s: failed to read manifest: %w", desc.ModuleName, err)
|
||||
}
|
||||
|
||||
logger := log.WithoutContext().WithFields(logrus.Fields{"plugin": "plugin-" + pName, "module": desc.ModuleName})
|
||||
logger := log.With().Str("plugin", "plugin-"+pName).Str("module", desc.ModuleName).Logger()
|
||||
|
||||
i := interp.New(interp.Options{
|
||||
GoPath: client.GoPath(),
|
||||
Env: os.Environ(),
|
||||
Stdout: logger.WriterLevel(logrus.DebugLevel),
|
||||
Stderr: logger.WriterLevel(logrus.ErrorLevel),
|
||||
Stdout: logs.NoLevel(logger, zerolog.DebugLevel),
|
||||
Stderr: logs.NoLevel(logger, zerolog.ErrorLevel),
|
||||
})
|
||||
|
||||
err = i.Use(stdlib.Symbols)
|
||||
|
@ -83,12 +85,13 @@ func NewBuilder(client *Client, plugins map[string]Descriptor, localPlugins map[
|
|||
return nil, fmt.Errorf("%s: failed to read manifest: %w", desc.ModuleName, err)
|
||||
}
|
||||
|
||||
logger := log.WithoutContext().WithFields(logrus.Fields{"plugin": "plugin-" + pName, "module": desc.ModuleName})
|
||||
logger := log.With().Str("plugin", "plugin-"+pName).Str("module", desc.ModuleName).Logger()
|
||||
|
||||
i := interp.New(interp.Options{
|
||||
GoPath: localGoPath,
|
||||
Env: os.Environ(),
|
||||
Stdout: logger.WriterLevel(logrus.DebugLevel),
|
||||
Stderr: logger.WriterLevel(logrus.ErrorLevel),
|
||||
Stdout: logs.NoLevel(logger, zerolog.DebugLevel),
|
||||
Stderr: logs.NoLevel(logger, zerolog.ErrorLevel),
|
||||
})
|
||||
|
||||
err = i.Use(stdlib.Symbols)
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const localGoPath = "./plugins-local/"
|
||||
|
@ -27,7 +27,7 @@ func SetupRemotePlugins(client *Client, plugins map[string]Descriptor) error {
|
|||
ctx := context.Background()
|
||||
|
||||
for pAlias, desc := range plugins {
|
||||
log.FromContext(ctx).Debugf("loading of plugin: %s: %s@%s", pAlias, desc.ModuleName, desc.Version)
|
||||
log.Ctx(ctx).Debug().Msgf("Loading of plugin: %s: %s@%s", pAlias, desc.ModuleName, desc.Version)
|
||||
|
||||
hash, err := client.Download(ctx, desc.ModuleName, desc.Version)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,8 +9,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"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/safe"
|
||||
"github.com/traefik/yaegi/interp"
|
||||
|
@ -158,21 +159,21 @@ func (p *Provider) Init() error {
|
|||
func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.WithoutContext().WithField(log.ProviderName, p.name).Errorf("panic inside the plugin %v", err)
|
||||
log.Error().Str(logs.ProviderName, p.name).Msgf("Panic inside the plugin %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
cfgChan := make(chan json.Marshaler)
|
||||
|
||||
pool.GoCtx(func(ctx context.Context) {
|
||||
logger := log.FromContext(log.With(ctx, log.Str(log.ProviderName, p.name)))
|
||||
logger := log.Ctx(ctx).With().Str(logs.ProviderName, p.name).Logger()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
err := p.pp.Stop()
|
||||
if err != nil {
|
||||
logger.Errorf("failed to stop the provider: %v", err)
|
||||
logger.Error().Err(err).Msg("Failed to stop the provider")
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -180,14 +181,14 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
|
|||
case cfgPg := <-cfgChan:
|
||||
marshalJSON, err := cfgPg.MarshalJSON()
|
||||
if err != nil {
|
||||
logger.Errorf("failed to marshal configuration: %v", err)
|
||||
logger.Error().Err(err).Msg("Failed to marshal configuration")
|
||||
continue
|
||||
}
|
||||
|
||||
cfg := &dynamic.Configuration{}
|
||||
err = json.Unmarshal(marshalJSON, cfg)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to unmarshal configuration: %v", err)
|
||||
logger.Error().Err(err).Msg("Failed to unmarshal configuration")
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue