diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-06-16 08:17:42 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-06-18 13:03:04 +0200 |
commit | 7c9fada778e91976d4ba1cbe942235a9bbeaf5cb (patch) | |
tree | a717f6e0a5915777ae6859564acd13385213bbab /deps | |
parent | 0e7944658660b5658b7640dce3cb346d7198d8c9 (diff) | |
download | hugo-7c9fada778e91976d4ba1cbe942235a9bbeaf5cb.tar.gz hugo-7c9fada778e91976d4ba1cbe942235a9bbeaf5cb.zip |
Replace the old log setup, with structured logging etc.
Fixes #11124
Diffstat (limited to 'deps')
-rw-r--r-- | deps/deps.go | 32 |
1 files changed, 18 insertions, 14 deletions
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 |