From 7c9fada778e91976d4ba1cbe942235a9bbeaf5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 16 Jun 2023 08:17:42 +0200 Subject: Replace the old log setup, with structured logging etc. Fixes #11124 --- hugolib/site.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'hugolib/site.go') diff --git a/hugolib/site.go b/hugolib/site.go index 035f543ee..fca8bca75 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -17,7 +17,6 @@ import ( "context" "fmt" "io" - "log" "mime" "net/url" "path" @@ -27,6 +26,7 @@ import ( "strings" "time" + "github.com/bep/logg" "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/htime" "github.com/gohugoio/hugo/common/hugio" @@ -285,7 +285,7 @@ func (s *Site) isEnabled(kind string) bool { type siteRefLinker struct { s *Site - errorLogger *log.Logger + errorLogger logg.LevelLogger notFoundURL string } @@ -302,11 +302,11 @@ func newSiteRefLinker(s *Site) (siteRefLinker, error) { func (s siteRefLinker) logNotFound(ref, what string, p page.Page, position text.Position) { if position.IsValid() { - s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q: %s: %s", s.s.Lang(), ref, position.String(), what) + s.errorLogger.Logf("[%s] REF_NOT_FOUND: Ref %q: %s: %s", s.s.Lang(), ref, position.String(), what) } else if p == nil { - s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q: %s", s.s.Lang(), ref, what) + s.errorLogger.Logf("[%s] REF_NOT_FOUND: Ref %q: %s", s.s.Lang(), ref, what) } else { - s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q from page %q: %s", s.s.Lang(), ref, p.Pathc(), what) + s.errorLogger.Logf("[%s] REF_NOT_FOUND: Ref %q from page %q: %s", s.s.Lang(), ref, p.Pathc(), what) } } @@ -507,9 +507,6 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro i18nChanged bool sourceFilesChanged = make(map[string]bool) - - // prevent spamming the log on changes - logger = helpers.NewDistinctErrorLogger() ) var cacheBusters []func(string) bool @@ -531,7 +528,7 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro switch id.Type { case files.ComponentFolderContent: - logger.Println("Source changed", ev) + s.Log.Println("Source changed", ev) sourceChanged = append(sourceChanged, ev) case files.ComponentFolderLayouts: tmplChanged = true @@ -539,16 +536,16 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro tmplAdded = true } if tmplAdded { - logger.Println("Template added", ev) + s.Log.Println("Template added", ev) } else { - logger.Println("Template changed", ev) + s.Log.Println("Template changed", ev) } case files.ComponentFolderData: - logger.Println("Data changed", ev) + s.Log.Println("Data changed", ev) dataChanged = true case files.ComponentFolderI18n: - logger.Println("i18n changed", ev) + s.Log.Println("i18n changed", ev) i18nChanged = true } -- cgit v1.2.3