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

32
deps/deps.go vendored
View File

@@ -3,12 +3,14 @@ package deps
import (
"context"
"fmt"
"io"
"path/filepath"
"sort"
"strings"
"sync"
"sync/atomic"
"github.com/bep/logg"
"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/config"
@@ -25,7 +27,6 @@ import (
"github.com/gohugoio/hugo/source"
"github.com/gohugoio/hugo/tpl"
"github.com/spf13/afero"
jww "github.com/spf13/jwalterweatherman"
)
// Deps holds dependencies used by many.
@@ -36,9 +37,6 @@ type Deps struct {
// The logger to use.
Log loggers.Logger `json:"-"`
// Used to log errors that may repeat itself many times.
LogDistinct loggers.Logger
ExecHelper *hexec.Exec
// The templates to use. This will usually implement the full tpl.TemplateManager.
@@ -117,15 +115,13 @@ func (d *Deps) Init() error {
}
if d.Log == nil {
d.Log = loggers.NewErrorLogger()
}
if d.LogDistinct == nil {
d.LogDistinct = helpers.NewDistinctLogger(d.Log)
d.Log = loggers.NewDefault()
}
if d.globalErrHandler == nil {
d.globalErrHandler = &globalErrHandler{}
d.globalErrHandler = &globalErrHandler{
logger: d.Log,
}
}
if d.BuildState == nil {
@@ -228,6 +224,8 @@ func (d *Deps) Compile(prototype *Deps) error {
}
type globalErrHandler struct {
logger loggers.Logger
// Channel for some "hard to get to" build errors
buildErrors chan error
// Used to signal that the build is done.
@@ -246,8 +244,7 @@ func (e *globalErrHandler) SendError(err error) {
}
return
}
jww.ERROR.Println(err)
e.logger.Errorln(err)
}
func (e *globalErrHandler) StartErrorCollector() chan error {
@@ -312,9 +309,16 @@ func (d *Deps) Close() error {
// on a global level, i.e. logging etc.
// Nil values will be given default values.
type DepsCfg struct {
// The logger to use. Only set in some tests.
// TODO(bep) get rid of this.
TestLogger loggers.Logger
// The Logger to use.
Logger loggers.Logger
// The logging level to use.
LogLevel logg.Level
// Where to write the logs.
// Currently we typically write everything to stdout.
LogOut io.Writer
// The file systems to use
Fs *hugofs.Fs