From 7c9fada778e91976d4ba1cbe942235a9bbeaf5cb Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Fri, 16 Jun 2023 08:17:42 +0200 Subject: Replace the old log setup, with structured logging etc. Fixes #11124 --- deps/deps.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'deps') diff --git a/deps/deps.go b/deps/deps.go index 39462de96..309555080 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -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 logging level to use. + LogLevel logg.Level - // The Logger to use. - Logger loggers.Logger + // Where to write the logs. + // Currently we typically write everything to stdout. + LogOut io.Writer // The file systems to use Fs *hugofs.Fs -- cgit v1.2.3