Replace the old log setup, with structured logging etc.

Fixes #11124
This commit is contained in:
Bjørn Erik Pedersen
2023-06-16 08:17:42 +02:00
parent 0e79446586
commit 7c9fada778
80 changed files with 1273 additions and 1082 deletions

View File

@@ -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
}