diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-06-16 08:17:42 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-06-18 13:03:04 +0200 |
commit | 7c9fada778e91976d4ba1cbe942235a9bbeaf5cb (patch) | |
tree | a717f6e0a5915777ae6859564acd13385213bbab /config | |
parent | 0e7944658660b5658b7640dce3cb346d7198d8c9 (diff) |
Replace the old log setup, with structured logging etc.
Fixes #11124
Diffstat (limited to 'config')
-rw-r--r-- | config/allconfig/allconfig.go | 3 | ||||
-rw-r--r-- | config/allconfig/load.go | 5 | ||||
-rw-r--r-- | config/commonConfig.go | 8 | ||||
-rw-r--r-- | config/commonConfig_test.go | 4 |
4 files changed, 14 insertions, 6 deletions
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go index 08792d870..ec7895eea 100644 --- a/config/allconfig/allconfig.go +++ b/config/allconfig/allconfig.go @@ -490,6 +490,9 @@ type RootConfig struct { // ENable to print warnings for multiple files published to the same destination. LogPathWarnings bool + // Enable to panic on warning log entries. This may make it easier to detect the source. + PanicOnWarning bool + // The configured environment. Default is "development" for server and "production" for build. Environment string diff --git a/config/allconfig/load.go b/config/allconfig/load.go index eca9d06df..4e5478c40 100644 --- a/config/allconfig/load.go +++ b/config/allconfig/load.go @@ -46,7 +46,7 @@ func LoadConfig(d ConfigSourceDescriptor) (*Configs, error) { } if d.Logger == nil { - d.Logger = loggers.NewErrorLogger() + d.Logger = loggers.NewDefault() } l := &configLoader{ConfigSourceDescriptor: d, cfg: config.New()} @@ -90,8 +90,9 @@ func LoadConfig(d ConfigSourceDescriptor) (*Configs, error) { return nil, fmt.Errorf("failed to init config: %w", err) } - // This is unfortunate, but this is a global setting. + // This is unfortunate, but these are global settings. tpl.SetSecurityAllowActionJSTmpl(configs.Base.Security.GoTemplates.AllowActionJSTmpl) + loggers.InitGlobalLogger(configs.Base.PanicOnWarning) return configs, nil diff --git a/config/commonConfig.go b/config/commonConfig.go index bd3e235bd..ac1dd39fa 100644 --- a/config/commonConfig.go +++ b/config/commonConfig.go @@ -19,6 +19,7 @@ import ( "sort" "strings" + "github.com/bep/logg" "github.com/gobwas/glob" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/common/types" @@ -306,6 +307,7 @@ func (c *CacheBuster) CompileConfig(logger loggers.Logger) error { if c.compiledSource != nil { return nil } + source := c.Source target := c.Target sourceRe, err := regexp.Compile(source) @@ -313,6 +315,8 @@ func (c *CacheBuster) CompileConfig(logger loggers.Logger) error { return fmt.Errorf("failed to compile cache buster source %q: %w", c.Source, err) } var compileErr error + debugl := logger.Logger().WithLevel(logg.LevelDebug).WithField(loggers.FieldNameCmd, "cachebuster") + c.compiledSource = func(s string) func(string) bool { m := sourceRe.FindStringSubmatch(s) matchString := "no match" @@ -320,7 +324,7 @@ func (c *CacheBuster) CompileConfig(logger loggers.Logger) error { if match { matchString = "match!" } - logger.Debugf("cachebuster: Matching %q with source %q: %s\n", s, source, matchString) + debugl.Logf("Matching %q with source %q: %s", s, source, matchString) if !match { return nil } @@ -341,7 +345,7 @@ func (c *CacheBuster) CompileConfig(logger loggers.Logger) error { if match { matchString = "match!" } - logger.Debugf("cachebuster: Matching %q with target %q: %s\n", s, target, matchString) + logger.Debugf("Matching %q with target %q: %s", s, target, matchString) return match } diff --git a/config/commonConfig_test.go b/config/commonConfig_test.go index 106069bdc..b8130eb0d 100644 --- a/config/commonConfig_test.go +++ b/config/commonConfig_test.go @@ -92,7 +92,7 @@ status = 301 s, err := DecodeServer(cfg) c.Assert(err, qt.IsNil) - c.Assert(s.CompileConfig(loggers.NewErrorLogger()), qt.IsNil) + c.Assert(s.CompileConfig(loggers.NewDefault()), qt.IsNil) c.Assert(s.MatchHeaders("/foo.jpg"), qt.DeepEquals, []types.KeyValueStr{ {Key: "X-Content-Type-Options", Value: "nosniff"}, @@ -145,7 +145,7 @@ func TestBuildConfigCacheBusters(t *testing.T) { c := qt.New(t) cfg := New() conf := DecodeBuildConfig(cfg) - l := loggers.NewInfoLogger() + l := loggers.NewDefault() c.Assert(conf.CompileConfig(l), qt.IsNil) m, err := conf.MatchCacheBuster(l, "assets/foo/main.js") |