aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.travis.yml4
-rw-r--r--commands/commandeer.go6
-rw-r--r--commands/commands.go10
-rw-r--r--commands/convert.go10
-rw-r--r--commands/hugo.go50
-rw-r--r--commands/server.go6
-rw-r--r--commands/static_syncer.go6
-rw-r--r--common/constants/constants.go4
-rw-r--r--common/loggers/ignorableLogger.go20
-rw-r--r--common/loggers/loggers.go139
-rw-r--r--common/loggers/loggers_test.go8
-rw-r--r--deps/deps.go14
-rw-r--r--helpers/content.go2
-rw-r--r--helpers/pathspec.go4
-rw-r--r--hugofs/nosymlink_fs.go4
-rw-r--r--hugofs/nosymlink_test.go4
-rw-r--r--hugofs/walk.go10
-rw-r--r--hugolib/alias.go10
-rw-r--r--hugolib/config.go2
-rw-r--r--hugolib/content_map_page.go2
-rw-r--r--hugolib/filesystems/basefs.go6
-rw-r--r--hugolib/hugo_modules_test.go2
-rw-r--r--hugolib/hugo_sites.go16
-rw-r--r--hugolib/hugo_sites_build.go7
-rw-r--r--hugolib/page.go4
-rw-r--r--hugolib/page__menus.go2
-rw-r--r--hugolib/page__meta.go8
-rw-r--r--hugolib/page__per_output.go4
-rw-r--r--hugolib/pages_capture.go6
-rw-r--r--hugolib/shortcode.go4
-rw-r--r--hugolib/site.go26
-rw-r--r--hugolib/site_render.go8
-rw-r--r--hugolib/testhelpers_test.go4
-rw-r--r--langs/i18n/i18n.go10
-rw-r--r--markup/asciidocext/convert.go18
-rw-r--r--markup/converter/converter.go2
-rw-r--r--markup/internal/external.go4
-rw-r--r--markup/org/convert.go6
-rw-r--r--markup/pandoc/convert.go2
-rw-r--r--markup/rst/convert.go4
-rw-r--r--modules/client.go12
-rw-r--r--modules/collect.go10
-rw-r--r--resources/page/pagemeta/page_frontmatter.go6
-rw-r--r--resources/resource_spec.go4
-rw-r--r--resources/resource_transformers/babel/babel.go4
-rw-r--r--resources/resource_transformers/postcss/postcss.go10
-rw-r--r--resources/transform.go4
-rw-r--r--tpl/data/data.go7
-rw-r--r--tpl/data/data_test.go8
-rw-r--r--tpl/data/resources.go6
-rw-r--r--tpl/data/resources_test.go6
-rw-r--r--tpl/fmt/fmt.go4
52 files changed, 318 insertions, 221 deletions
diff --git a/.travis.yml b/.travis.yml
index 5b8a1fb2d..9ff6029b1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -72,6 +72,6 @@ script:
HUGO_TIMEOUT=30000 mage -v check;
fi
- mage -v hugo
- - ./hugo -s docs/
- - ./hugo --renderToMemory -s docs/
+ - HUGO_IGNOREERRORS=error-remote-getjson ./hugo -s docs/
+ - HUGO_IGNOREERRORS=error-remote-getjson ./hugo --renderToMemory -s docs/
- df -h
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 52a47484f..e0eae4a66 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -60,7 +60,7 @@ type commandeerHugoState struct {
type commandeer struct {
*commandeerHugoState
- logger *loggers.Logger
+ logger loggers.Logger
serverConfig *config.Server
// Currently only set when in "fast render mode". But it seems to
@@ -112,7 +112,7 @@ func (c *commandeerHugoState) hugo() *hugolib.HugoSites {
}
func (c *commandeer) errCount() int {
- return int(c.logger.ErrorCounter.Count())
+ return int(c.logger.LogCounters().ErrorCounter.Count())
}
func (c *commandeer) getErrorWithContext() interface{} {
@@ -415,7 +415,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
}
config.Set("cacheDir", cacheDir)
- cfg.Logger.INFO.Println("Using config file:", config.ConfigFileUsed())
+ cfg.Logger.Infoln("Using config file:", config.ConfigFileUsed())
return nil
diff --git a/commands/commands.go b/commands/commands.go
index ddacc7cf3..ce5f0ff7d 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -322,16 +322,12 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) {
_ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
}
-func checkErr(logger *loggers.Logger, err error, s ...string) {
+func checkErr(logger loggers.Logger, err error, s ...string) {
if err == nil {
return
}
- if len(s) == 0 {
- logger.CRITICAL.Println(err)
- return
- }
for _, message := range s {
- logger.ERROR.Println(message)
+ logger.Errorln(message)
}
- logger.ERROR.Println(err)
+ logger.Errorln(err)
}
diff --git a/commands/convert.go b/commands/convert.go
index fe64405e9..d8976f7ea 100644
--- a/commands/convert.go
+++ b/commands/convert.go
@@ -123,7 +123,7 @@ func (cc *convertCmd) convertContents(format metadecoders.Format) error {
site := h.Sites[0]
- site.Log.FEEDBACK.Println("processing", len(site.AllPages()), "content files")
+ site.Log.Println("processing", len(site.AllPages()), "content files")
for _, p := range site.AllPages() {
if err := cc.convertAndSavePage(p, site, format); err != nil {
return err
@@ -147,19 +147,19 @@ func (cc *convertCmd) convertAndSavePage(p page.Page, site *hugolib.Site, target
errMsg := fmt.Errorf("Error processing file %q", p.Path())
- site.Log.INFO.Println("Attempting to convert", p.File().Filename())
+ site.Log.Infoln("Attempting to convert", p.File().Filename())
f := p.File()
file, err := f.FileInfo().Meta().Open()
if err != nil {
- site.Log.ERROR.Println(errMsg)
+ site.Log.Errorln(errMsg)
file.Close()
return nil
}
pf, err := pageparser.ParseFrontMatterAndContent(file)
if err != nil {
- site.Log.ERROR.Println(errMsg)
+ site.Log.Errorln(errMsg)
file.Close()
return err
}
@@ -179,7 +179,7 @@ func (cc *convertCmd) convertAndSavePage(p page.Page, site *hugolib.Site, target
var newContent bytes.Buffer
err = parser.InterfaceToFrontMatter(pf.FrontMatter, targetFormat, &newContent)
if err != nil {
- site.Log.ERROR.Println(errMsg)
+ site.Log.Errorln(errMsg)
return err
}
diff --git a/commands/hugo.go b/commands/hugo.go
index 7eaaedbc9..058f1ec7c 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -130,7 +130,7 @@ func initializeConfig(mustHaveConfigFile, running bool,
}
-func (c *commandeer) createLogger(cfg config.Provider, running bool) (*loggers.Logger, error) {
+func (c *commandeer) createLogger(cfg config.Provider, running bool) (loggers.Logger, error) {
var (
logHandle = ioutil.Discard
logThreshold = jww.LevelWarn
@@ -374,12 +374,12 @@ func (c *commandeer) initMemProfile() {
f, err := os.Create(c.h.memprofile)
if err != nil {
- c.logger.ERROR.Println("could not create memory profile: ", err)
+ c.logger.Errorf("could not create memory profile: ", err)
}
defer f.Close()
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
- c.logger.ERROR.Println("could not write memory profile: ", err)
+ c.logger.Errorf("could not write memory profile: ", err)
}
}
@@ -518,7 +518,7 @@ func (c *commandeer) build() error {
if createCounter, ok := c.destinationFs.(hugofs.DuplicatesReporter); ok {
dupes := createCounter.ReportDuplicates()
if dupes != "" {
- c.logger.WARN.Println("Duplicate target paths:", dupes)
+ c.logger.Warnln("Duplicate target paths:", dupes)
}
}
}
@@ -532,8 +532,8 @@ func (c *commandeer) build() error {
baseWatchDir := c.Cfg.GetString("workingDir")
rootWatchDirs := getRootWatchDirsStr(baseWatchDir, watchDirs)
- c.logger.FEEDBACK.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
- c.logger.FEEDBACK.Println("Press Ctrl+C to stop")
+ c.logger.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
+ c.logger.Println("Press Ctrl+C to stop")
watcher, err := c.newWatcher(watchDirs...)
checkErr(c.Logger, err)
defer watcher.Close()
@@ -590,7 +590,7 @@ func (c *commandeer) doWithPublishDirs(f func(sourceFs *filesystems.SourceFilesy
staticFilesystems := c.hugo().BaseFs.SourceFilesystems.Static
if len(staticFilesystems) == 0 {
- c.logger.INFO.Println("No static directories found to sync")
+ c.logger.Infoln("No static directories found to sync")
return langCount, nil
}
@@ -662,13 +662,13 @@ func (c *commandeer) copyStaticTo(sourceFs *filesystems.SourceFilesystem) (uint6
syncer.Delete = c.Cfg.GetBool("cleanDestinationDir")
if syncer.Delete {
- c.logger.INFO.Println("removing all files from destination that don't exist in static dirs")
+ c.logger.Infoln("removing all files from destination that don't exist in static dirs")
syncer.DeleteFilter = func(f os.FileInfo) bool {
return f.IsDir() && strings.HasPrefix(f.Name(), ".")
}
}
- c.logger.INFO.Println("syncing static files to", publishDir)
+ c.logger.Infoln("syncing static files to", publishDir)
// because we are using a baseFs (to get the union right).
// set sync src to root
@@ -689,7 +689,7 @@ func (c *commandeer) firstPathSpec() *helpers.PathSpec {
func (c *commandeer) timeTrack(start time.Time, name string) {
elapsed := time.Since(start)
- c.logger.FEEDBACK.Printf("%s in %v ms", name, int(1000*elapsed.Seconds()))
+ c.logger.Printf("%s in %v ms", name, int(1000*elapsed.Seconds()))
}
// getDirList provides NewWatcher() with a list of directories to watch for changes.
@@ -698,7 +698,7 @@ func (c *commandeer) getDirList() ([]string, error) {
walkFn := func(path string, fi hugofs.FileMetaInfo, err error) error {
if err != nil {
- c.logger.ERROR.Println("walker: ", err)
+ c.logger.Errorln("walker: ", err)
return nil
}
@@ -724,7 +724,7 @@ func (c *commandeer) getDirList() ([]string, error) {
w := hugofs.NewWalkway(hugofs.WalkwayConfig{Logger: c.logger, Info: fi, WalkFn: walkFn})
if err := w.Walk(); err != nil {
- c.logger.ERROR.Println("walker: ", err)
+ c.logger.Errorln("walker: ", err)
}
}
@@ -740,8 +740,8 @@ func (c *commandeer) buildSites() (err error) {
func (c *commandeer) handleBuildErr(err error, msg string) {
c.buildErr = err
- c.logger.ERROR.Print(msg + ":\n\n")
- c.logger.ERROR.Println(helpers.FirstUpper(err.Error()))
+ c.logger.Errorln(msg + ":\n")
+ c.logger.Errorln(helpers.FirstUpper(err.Error()))
if !c.h.quiet && c.h.verbose {
herrors.PrintStackTraceFromErr(err)
}
@@ -822,13 +822,13 @@ func (c *commandeer) fullRebuild(changeType string) {
if !c.paused {
_, err := c.copyStatic()
if err != nil {
- c.logger.ERROR.Println(err)
+ c.logger.Errorln(err)
return
}
err = c.buildSites()
if err != nil {
- c.logger.ERROR.Println(err)
+ c.logger.Errorln(err)
} else if !c.h.buildWatch && !c.Cfg.GetBool("disableLiveReload") {
livereload.ForceRefresh()
}
@@ -862,7 +862,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
// Identifies changes to config (config.toml) files.
configSet := make(map[string]bool)
- c.logger.FEEDBACK.Println("Watching for config changes in", strings.Join(c.configFiles, ", "))
+ c.logger.Println("Watching for config changes in", strings.Join(c.configFiles, ", "))
for _, configFile := range c.configFiles {
watcher.Add(configFile)
configSet[configFile] = true
@@ -879,7 +879,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
}
case err := <-watcher.Errors:
if err != nil {
- c.logger.ERROR.Println("Error while watching:", err)
+ c.logger.Errorln("Error while watching:", err)
}
}
}
@@ -895,9 +895,9 @@ func (c *commandeer) printChangeDetected(typ string) {
}
msg += " detected, rebuilding site."
- c.logger.FEEDBACK.Println(msg)
+ c.logger.Println(msg)
const layout = "2006-01-02 15:04:05.000 -0700"
- c.logger.FEEDBACK.Println(time.Now().Format(layout))
+ c.logger.Println(time.Now().Format(layout))
}
const (
@@ -979,7 +979,7 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
return
}
- c.logger.INFO.Println("Received System Events:", evs)
+ c.logger.Infoln("Received System Events:", evs)
staticEvents := []fsnotify.Event{}
dynamicEvents := []fsnotify.Event{}
@@ -1059,7 +1059,7 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
walkAdder := func(path string, f hugofs.FileMetaInfo, err error) error {
if f.IsDir() {
- c.logger.FEEDBACK.Println("adding created directory to watchlist", path)
+ c.logger.Println("adding created directory to watchlist", path)
if err := watcher.Add(path); err != nil {
return err
}
@@ -1091,15 +1091,15 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
c.printChangeDetected("Static files")
if c.Cfg.GetBool("forceSyncStatic") {
- c.logger.FEEDBACK.Printf("Syncing all static files\n")
+ c.logger.Printf("Syncing all static files\n")
_, err := c.copyStatic()
if err != nil {
- c.logger.ERROR.Println("Error copying static files to publish dir:", err)
+ c.logger.Errorln("Error copying static files to publish dir:", err)
return
}
} else {
if err := staticSyncer.syncsStaticEvents(staticEvents); err != nil {
- c.logger.ERROR.Println("Error syncing static files to publish dir:", err)
+ c.logger.Errorln("Error syncing static files to publish dir:", err)
return
}
}
diff --git a/commands/server.go b/commands/server.go
index 7d604b97d..b6a8d282c 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -185,7 +185,7 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error {
// port set explicitly by user -- he/she probably meant it!
err = newSystemErrorF("Server startup failed: %s", err)
}
- c.logger.FEEDBACK.Println("port", sc.serverPort, "already in use, attempting to use an available port")
+ c.logger.Println("port", sc.serverPort, "already in use, attempting to use an available port")
sp, err := helpers.FindAvailablePort()
if err != nil {
err = newSystemError("Unable to find alternative port to use:", err)
@@ -350,7 +350,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro
w.WriteHeader(500)
r, err := f.errorTemplate(err)
if err != nil {
- f.c.logger.ERROR.Println(err)
+ f.c.logger.Errorln(err)
}
port = 1313
@@ -508,7 +508,7 @@ func (c *commandeer) serve(s *serverCmd) error {
go func() {
err = http.ListenAndServe(endpoint, mu)
if err != nil {
- c.logger.ERROR.Printf("Error: %s\n", err.Error())
+ c.logger.Errorf("Error: %s\n", err.Error())
os.Exit(1)
}
}()
diff --git a/commands/static_syncer.go b/commands/static_syncer.go
index 62ef28b2c..17fae7d13 100644
--- a/commands/static_syncer.go
+++ b/commands/static_syncer.go
@@ -107,10 +107,10 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error {
logger.Println("Syncing", relPath, "to", publishDir)
if err := syncer.Sync(filepath.Join(publishDir, relPath), relPath); err != nil {
- c.logger.ERROR.Println(err)
+ c.logger.Errorln(err)
}
} else {
- c.logger.ERROR.Println(err)
+ c.logger.Errorln(err)
}
continue
@@ -119,7 +119,7 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error {
// For all other event operations Hugo will sync static.
logger.Println("Syncing", relPath, "to", publishDir)
if err := syncer.Sync(filepath.Join(publishDir, relPath), relPath); err != nil {
- c.logger.ERROR.Println(err)
+ c.logger.Errorln(err)
}
}
diff --git a/common/constants/constants.go b/common/constants/constants.go
index 25bd7c758..e416d4ad3 100644
--- a/common/constants/constants.go
+++ b/common/constants/constants.go
@@ -18,4 +18,8 @@ package constants
const (
ErrIDAmbigousDisableKindTaxonomy = "error-disable-taxonomy"
ErrIDAmbigousOutputKindTaxonomy = "error-output-taxonomy"
+
+ // IDs for remote errors in tpl/data.
+ ErrRemoteGetJSON = "error-remote-getjson"
+ ErrRemoteGetCSV = "error-remote-getcsv"
)
diff --git a/common/loggers/ignorableLogger.go b/common/loggers/ignorableLogger.go
index e12e41d68..1bd4d99b8 100644
--- a/common/loggers/ignorableLogger.go
+++ b/common/loggers/ignorableLogger.go
@@ -19,25 +19,31 @@ import (
)
// IgnorableLogger is a logger that ignores certain log statements.
-type IgnorableLogger struct {
- logger *Logger
+type IgnorableLogger interface {
+ Logger
+ Errorsf(statementID, format string, v ...interface{})
+}
+
+type ignorableLogger struct {
+ Logger
statements map[string]bool
}
// NewIgnorableLogger wraps the given logger and ignores the log statement IDs given.
-func NewIgnorableLogger(logger *Logger, statements ...string) IgnorableLogger {
+func NewIgnorableLogger(logger Logger, statements ...string) IgnorableLogger {
statementsSet := make(map[string]bool)
for _, s := range statements {
statementsSet[strings.ToLower(s)] = true
}
- return IgnorableLogger{
- logger: logger,
+ return ignorableLogger{
+ Logger: logger,
statements: statementsSet,
}
}
-func (l IgnorableLogger) Errorf(statementID, format string, v ...interface{}) {
+// Errorsf logs statementID as an ERROR if not configured as ignoreable.
+func (l ignorableLogger) Errorsf(statementID, format string, v ...interface{}) {
if l.statements[statementID] {
// Ignore.
return
@@ -48,5 +54,5 @@ ignoreErrors = [%q]`, statementID)
format += ignoreMsg
- l.logger.ERROR.Printf(format, v...)
+ l.Errorf(format, v...)
}
diff --git a/common/loggers/loggers.go b/common/loggers/loggers.go
index d406e5f20..5c04b9eab 100644
--- a/common/loggers/loggers.go
+++ b/common/loggers/loggers.go
@@ -1,4 +1,4 @@
-// Copyright 2018 The Hugo Authors. All rights reserved.
+// Copyright 2020 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -56,39 +56,122 @@ func (w prefixWriter) Write(p []byte) (n int, err error) {
return len(p), nil
}
-// Logger wraps a *loggers.Logger and some other related logging state.
-type Logger struct {
+type Logger interface {
+ Printf(format string, v ...interface{})
+ Println(v ...interface{})
+ PrintTimerIfDelayed(start time.Time, name string)
+ Debug() *log.Logger
+ Info() *log.Logger
+ Infof(format string, v ...interface{})
+ Infoln(v ...interface{})
+ Warn() *log.Logger
+ Warnf(format string, v ...interface{})
+ Warnln(v ...interface{})
+ Error() *log.Logger
+ Errorf(format string, v ...interface{})
+ Errorln(v ...interface{})
+ Errors() string
+
+ Out() io.Writer
+
+ Reset()
+
+ // Used in tests.
+ LogCounters() *LogCounters
+}
+
+type LogCounters struct {
+ ErrorCounter *jww.Counter
+ WarnCounter *jww.Counter
+}
+
+type logger struct {
*jww.Notepad
// The writer that represents stdout.
// Will be ioutil.Discard when in quiet mode.
- Out io.Writer
+ out io.Writer
- ErrorCounter *jww.Counter
- WarnCounter *jww.Counter
+ logCounters *LogCounters
// This is only set in server mode.
errors *bytes.Buffer
}
+func (l *logger) Printf(format string, v ...interface{}) {
+ l.FEEDBACK.Printf(format, v...)
+}
+
+func (l *logger) Println(v ...interface{}) {
+ l.FEEDBACK.Println(v...)
+}
+
+func (l *logger) Debug() *log.Logger {
+ return l.DEBUG
+}
+
+func (l *logger) Infof(format string, v ...interface{}) {
+ l.INFO.Printf(format, v...)
+}
+
+func (l *logger) Infoln(v ...interface{}) {
+ l.INFO.Println(v...)
+}
+
+func (l *logger) Info() *log.Logger {
+ return l.INFO
+}
+
+func (l *logger) Warnf(format string, v ...interface{}) {
+ l.WARN.Printf(format, v...)
+}
+
+func (l *logger) Warnln(v ...interface{}) {
+ l.WARN.Println(v...)
+}
+
+func (l *logger) Warn() *log.Logger {
+ return l.WARN
+}
+
+func (l *logger) Errorf(format string, v ...interface{}) {
+ l.ERROR.Printf(format, v...)
+}
+
+func (l *logger) Errorln(v ...interface{}) {
+ l.ERROR.Println(v...)
+}
+
+func (l *logger) Error() *log.Logger {
+ return l.ERROR
+}
+
+func (l *logger) LogCounters() *LogCounters {
+ return l.logCounters
+}
+
+func (l *logger) Out() io.Writer {
+ return l.out
+}
+
// PrintTimerIfDelayed prints a time statement to the FEEDBACK logger
// if considerable time is spent.
-func (l *Logger) PrintTimerIfDelayed(start time.Time, name string) {
+func (l *logger) PrintTimerIfDelayed(start time.Time, name string) {
elapsed := time.Since(start)
milli := int(1000 * elapsed.Seconds())
if milli < 500 {
return
}
- l.FEEDBACK.Printf("%s in %v ms", name, milli)
+ l.Printf("%s in %v ms", name, milli)
}
-func (l *Logger) PrintTimer(start time.Time, name string) {
+func (l *logger) PrintTimer(start time.Time, name string) {
elapsed := time.Since(start)
milli := int(1000 * elapsed.Seconds())
- l.FEEDBACK.Printf("%s in %v ms", name, milli)
+ l.Printf("%s in %v ms", name, milli)
}
-func (l *Logger) Errors() string {
+func (l *logger) Errors() string {
if l.errors == nil {
return ""
}
@@ -96,45 +179,45 @@ func (l *Logger) Errors() string {
}
// Reset resets the logger's internal state.
-func (l *Logger) Reset() {
- l.ErrorCounter.Reset()
+func (l *logger) Reset() {
+ l.logCounters.ErrorCounter.Reset()
if l.errors != nil {
l.errors.Reset()
}
}
// NewLogger creates a new Logger for the given thresholds
-func NewLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) *Logger {
+func NewLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) Logger {
return newLogger(stdoutThreshold, logThreshold, outHandle, logHandle, saveErrors)
}
// NewDebugLogger is a convenience function to create a debug logger.
-func NewDebugLogger() *Logger {
+func NewDebugLogger() Logger {
return NewBasicLogger(jww.LevelDebug)
}
// NewWarningLogger is a convenience function to create a warning logger.
-func NewWarningLogger() *Logger {
+func NewWarningLogger() Logger {
return NewBasicLogger(jww.LevelWarn)
}
// NewInfoLogger is a convenience function to create a info logger.
-func NewInfoLogger() *Logger {
+func NewInfoLogger() Logger {
return NewBasicLogger(jww.LevelInfo)
}
// NewErrorLogger is a convenience function to create an error logger.
-func NewErrorLogger() *Logger {
+func NewErrorLogger() Logger {
return NewBasicLogger(jww.LevelError)
}
// NewBasicLogger creates a new basic logger writing to Stdout.
-func NewBasicLogger(t jww.Threshold) *Logger {
+func NewBasicLogger(t jww.Threshold) Logger {
return newLogger(t, jww.LevelError, os.Stdout, ioutil.Discard, false)
}
// NewBasicLoggerForWriter creates a new basic logger writing to w.
-func NewBasicLoggerForWriter(t jww.Threshold, w io.Writer) *Logger {
+func NewBasicLoggerForWriter(t jww.Threshold, w io.Writer) Logger {
return newLogger(t, jww.LevelError, w, ioutil.Discard, false)
}
@@ -219,7 +302,7 @@ var fatalLogListener = func(t jww.Threshold) io.Writer {
return new(fatalLogWriter)
}
-func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) *Logger {
+func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) *logger {
errorCounter := &jww.Counter{}
warnCounter := &jww.Counter{}
outHandle, logHandle = getLogWriters(outHandle, logHandle)
@@ -239,11 +322,13 @@ func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle
listeners = append(listeners, errorCapture)
}
- return &Logger{
- Notepad: jww.NewNotepad(stdoutThreshold, logThreshold, outHandle, logHandle, "", log.Ldate|log.Ltime, listeners...),
- Out: outHandle,
- ErrorCounter: errorCounter,
- WarnCounter: warnCounter,
- errors: errorBuff,
+ return &logger{
+ Notepad: jww.NewNotepad(stdoutThreshold, logThreshold, outHandle, logHandle, "", log.Ldate|log.Ltime, listeners...),
+ out: outHandle,
+ logCounters: &LogCounters{
+ ErrorCounter: errorCounter,
+ WarnCounter: warnCounter,
+ },
+ errors: errorBuff,
}
}
diff --git a/common/loggers/loggers_test.go b/common/loggers/loggers_test.go
index bf52d97c1..7af3ca9da 100644
--- a/common/loggers/loggers_test.go
+++ b/common/loggers/loggers_test.go
@@ -26,11 +26,11 @@ func TestLogger(t *testing.T) {
c := qt.New(t)
l := NewWarningLogger()
- l.ERROR.Println("One error")
- l.ERROR.Println("Two error")
- l.WARN.Println("A warning")
+ l.Errorln("One error")
+ l.Errorln("Two error")
+ l.Warnln("A warning")
- c.Assert(l.ErrorCounter.Count(), qt.Equals, uint64(2))
+ c.Assert(l.LogCounters().ErrorCounter.Count(), qt.Equals, uint64(2))
}
diff --git a/deps/deps.go b/deps/deps.go
index cfd39bf7d..b70dcb5a0 100644
--- a/deps/deps.go
+++ b/deps/deps.go
@@ -21,6 +21,7 @@ import (
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/source"
"github.com/gohugoio/hugo/tpl"
+ "github.com/spf13/cast"
jww "github.com/spf13/jwalterweatherman"
)
@@ -30,7 +31,7 @@ import (
type Deps struct {
// The logger to use.
- Log *loggers.Logger `json:"-"`
+ Log loggers.Logger `json:"-"`
// Used to log errors that may repeat itself many times.
DistinctErrorLog *helpers.DistinctLogger
@@ -260,12 +261,15 @@ func New(cfg DepsCfg) (*Deps, error) {
timeoutms = 3000
}
- distinctErrorLogger := helpers.NewDistinctLogger(logger.ERROR)
- distinctWarnLogger := helpers.NewDistinctLogger(logger.WARN)
+ ignoreErrors := cast.ToStringSlice(cfg.Cfg.Get("ignoreErrors"))
+ ignorableLogger := loggers.NewIgnorableLogger(logger, ignoreErrors...)
+
+ distinctErrorLogger := helpers.NewDistinctLogger(logger.Error())
+ distinctWarnLogger := helpers.NewDistinctLogger(logger.Warn())
d := &Deps{
Fs: fs,
- Log: logger,
+ Log: ignorableLogger,
DistinctErrorLog: distinctErrorLogger,
DistinctWarningLog: distinctWarnLogger,
templateProvider: cfg.TemplateProvider,
@@ -350,7 +354,7 @@ func (d Deps) ForLanguage(cfg DepsCfg, onCreated func(d *Deps) error) (*Deps, er
type DepsCfg struct {
// The Logger to use.
- Logger *loggers.Logger
+ Logger loggers.Logger
// The file systems to use
Fs *hugofs.Fs
diff --git a/helpers/content.go b/helpers/content.go
index 5eeca88b6..c59e41a8c 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -65,7 +65,7 @@ type ContentSpec struct {
// NewContentSpec returns a ContentSpec initialized
// with the appropriate fields from the given config.Provider.
-func NewContentSpec(cfg config.Provider, logger *loggers.Logger, contentFs afero.Fs) (*ContentSpec, error) {
+func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.Fs) (*ContentSpec, error) {
spec := &ContentSpec{
summaryLength: cfg.GetInt("summaryLength"),
diff --git a/helpers/pathspec.go b/helpers/pathspec.go
index d61757b3d..557261f1c 100644
--- a/helpers/pathspec.go
+++ b/helpers/pathspec.go
@@ -38,13 +38,13 @@ type PathSpec struct {
}
// NewPathSpec creats a new PathSpec from the given filesystems and language.
-func NewPathSpec(fs *hugofs.Fs, cfg config.Provider, logger *loggers.Logger) (*PathSpec, error) {
+func NewPathSpec(fs *hugofs.Fs, cfg config.Provider, logger loggers.Logger) (*PathSpec, error) {
return NewPathSpecWithBaseBaseFsProvided(fs, cfg, logger, nil)
}
// NewPathSpecWithBaseBaseFsProvided creats a new PathSpec from the given filesystems and language.
// If an existing BaseFs is provided, parts of that is reused.
-func NewPathSpecWithBaseBaseFsProvided(fs *hugofs.Fs, cfg config.Provider, logger *loggers.Logger, baseBaseFs *filesystems.BaseFs) (*PathSpec, error) {
+func NewPathSpecWithBaseBaseFsProvided(fs *hugofs.Fs, cfg config.Provider, logger loggers.Logger, baseBaseFs *filesystems.BaseFs) (*PathSpec, error) {
p, err := paths.New(fs, cfg)
if err != nil {
diff --git a/hugofs/nosymlink_fs.go b/hugofs/nosymlink_fs.go
index 409b6f03d..fa89d61e0 100644
--- a/hugofs/nosymlink_fs.go
+++ b/hugofs/nosymlink_fs.go
@@ -28,14 +28,14 @@ var (
)
// NewNoSymlinkFs creates a new filesystem that prevents symlinks.
-func NewNoSymlinkFs(fs afero.Fs, logger *loggers.Logger, allowFiles bool) afero.Fs {
+func NewNoSymlinkFs(fs afero.Fs, logger loggers.Logger, allowFiles bool) afero.Fs {
return &noSymlinkFs{Fs: fs, logger: logger, allowFiles: allowFiles}
}
// noSymlinkFs is a filesystem that prevents symlinking.
type noSymlinkFs struct {
allowFiles bool // block dirs only
- logger *loggers.Logger
+ logger loggers.Logger
afero.Fs
}
diff --git a/hugofs/nosymlink_test.go b/hugofs/nosymlink_test.go
index c938da006..f541fc0a7 100644
--- a/hugofs/nosymlink_test.go
+++ b/hugofs/nosymlink_test.go
@@ -68,7 +68,7 @@ func TestNoSymlinkFs(t *testing.T) {
for _, bfs := range []afero.Fs{NewBaseFileDecorator(Os), Os} {
for _, allowFiles := range []bool{false, true} {
- logger.WarnCounter.Reset()
+ logger.LogCounters().WarnCounter.Reset()
fs := NewNoSymlinkFs(bfs, logger, allowFiles)
ls := fs.(afero.Lstater)
symlinkedDir := filepath.Join(workDir, "symlinkdedir")
@@ -139,7 +139,7 @@ func TestNoSymlinkFs(t *testing.T) {
_, err = f.Readdir(-1)
c.Assert(err, qt.IsNil)
f.Close()
- c.Assert(logger.WarnCounter.Count(), qt.Equals, uint64(1))
+ c.Assert(logger.LogCounters().WarnCounter.Count(), qt.Equals, uint64(1))
}
}
diff --git a/hugofs/walk.go b/hugofs/walk.go
index da6983f11..91dd386e2 100644
--- a/hugofs/walk.go
+++ b/hugofs/walk.go
@@ -37,7 +37,7 @@ type Walkway struct {
root string
basePath string
- logger *loggers.Logger
+ logger loggers.Logger
// May be pre-set
fi FileMetaInfo
@@ -59,7 +59,7 @@ type WalkwayConfig struct {
Root string
BasePath string
- Logger *loggers.Logger
+ Logger loggers.Logger
// One or both of these may be pre-set.
Info FileMetaInfo
@@ -158,15 +158,15 @@ func (w *Walkway) checkErr(filename string, err error) bool {
// The file may be removed in process.
// This may be a ERROR situation, but it is not possible
// to determine as a general case.
- w.logger.WARN.Printf("File %q not found, skipping.", filename)
+ w.logger.Warnf("File %q not found, skipping.", filename)
return true
}
return false
}
-func logUnsupportedSymlink(filename string, logger *loggers.Logger) {
- logger.WARN.Printf("Unsupported symlink found in %q, skipping.", filename)
+func logUnsupportedSymlink(filename string, logger loggers.Logger) {
+ logger.Warnf("Unsupported symlink found in %q, skipping.", filename)
}
// walk recursively descends path, calling walkFn.
diff --git a/hugolib/alias.go b/hugolib/alias.go
index c1f668d41..6272b7910 100644
--- a/hugolib/alias.go
+++ b/hugolib/alias.go
@@ -33,11 +33,11 @@ import (
type aliasHandler struct {
t tpl.TemplateHandler
- log *loggers.Logger
+ log loggers.Logger
allowRoot bool
}
-func newAliasHandler(t tpl.TemplateHandler, l *loggers.Logger, allowRoot bool) aliasHandler {
+func newAliasHandler(t tpl.TemplateHandler, l loggers.Logger, allowRoot bool) aliasHandler {
return aliasHandler{t, l, allowRoot}
}
@@ -80,7 +80,7 @@ func (s *Site) writeDestAlias(path, permalink string, outputFormat output.Format
func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, outputFormat output.Format, p page.Page) (err error) {
handler := newAliasHandler(s.Tmpl(), s.Log, allowRoot)
- s.Log.DEBUG.Println("creating alias:", path, "redirecting to", permalink)
+ s.Log.Debug().Println("creating alias:", path, "redirecting to", permalink)
targetPath, err := handler.targetPathAlias(path)
if err != nil {
@@ -153,12 +153,12 @@ func (a aliasHandler) targetPathAlias(src string) (string, error) {
if len(msgs) > 0 {
if runtime.GOOS == "windows" {
for _, m := range msgs {
- a.log.ERROR.Println(m)
+ a.log.Errorln(m)
}
return "", fmt.Errorf("cannot create \"%s\": Windows filename restriction", originalAlias)
}
for _, m := range msgs {
- a.log.INFO.Println(m)
+ a.log.Infoln(m)
}
}
diff --git a/hugolib/config.go b/hugolib/config.go
index cab2013ca..7500dfc72 100644
--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -74,7 +74,7 @@ func loadSiteConfig(cfg config.Provider) (scfg SiteConfig, err error) {
// ConfigSourceDescriptor describes where to find the config (e.g. config.toml etc.).
type ConfigSourceDescriptor struct {
Fs afero.Fs
- Logger *loggers.Logger
+ Logger loggers.Logger
// Path to the config file to use, e.g. /my/project/config.toml
Filename string
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index b2a8fda7e..e79228ba3 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -581,7 +581,7 @@ func (m *pageMap) attachPageToViews(s string, b *contentNode) {
w := getParamToLower(b.p, viewName.plural+"_weight")
weight, err := cast.ToIntE(w)
if err != nil {
- m.s.Log.ERROR.Printf("Unable to convert taxonomy weight %#v to int for %q", w, b.p.Path())
+ m.s.Log.Errorf("Unable to convert taxonomy weight %#v to int for %q", w, b.p.Path())
// weight will equal zero, so let the flow continue
}
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go
index 76d49055c..189aa19c6 100644
--- a/hugolib/filesystems/basefs.go
+++ b/hugolib/filesystems/basefs.go
@@ -359,7 +359,7 @@ func WithBaseFs(b *BaseFs) func(*BaseFs) error {
}
// NewBase builds the filesystems used by Hugo given the paths and options provided.NewBase
-func NewBase(p *paths.Paths, logger *loggers.Logger, options ...func(*BaseFs) error) (*BaseFs, error) {
+func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) error) (*BaseFs, error) {
fs := p.Fs
if logger == nil {
logger = loggers.NewWarningLogger()
@@ -396,14 +396,14 @@ func NewBase(p *paths.Paths, logger *loggers.Logger, options ...func(*BaseFs) er
}
type sourceFilesystemsBuilder struct {
- logger *loggers.Logger
+ logger loggers.Logger
p *paths.Paths
sourceFs afero.Fs
result *SourceFilesystems
theBigFs *filesystemsCollector
}
-func newSourceFilesystemsBuilder(p *paths.Paths, logger *loggers.Logger, b *BaseFs) *sourceFilesystemsBuilder {
+func newSourceFilesystemsBuilder(p *paths.Paths, logger loggers.Logger, b *BaseFs) *sourceFilesystemsBuilder {
sourceFs := hugofs.NewBaseFileDecorator(p.Fs.Source)
return &sourceFilesystemsBuilder{p: p, logger: logger, sourceFs: sourceFs, theBigFs: b.theBigFs, result: &SourceFilesystems{}}
}
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go
index 87cddf086..b2ab59ef0 100644
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -649,7 +649,7 @@ min_version = 0.55.0
c := qt.New(t)
- c.Assert(logger.WarnCounter.Count(), qt.Equals, uint64(3))
+ c.Assert(logger.LogCounters().WarnCounter.Count(), qt.Equals, uint64(3))
}
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 702e51abb..1a6a07b03 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -223,7 +223,7 @@ func (h *HugoSites) pickOneAndLogTheRest(errors []error) error {
break
}
- h.Log.ERROR.Println(err)
+ h.Log.Errorln(err)
}
return errors[i]
@@ -246,7 +246,7 @@ func (h *HugoSites) NumLogErrors() int {
if h == nil {
return 0
}
- return int(h.Log.ErrorCounter.Count())
+ return int(h.Log.LogCounters().ErrorCounter.Count())
}
func (h *HugoSites) PrintProcessingStats(w io.Writer) {
@@ -386,7 +386,7 @@ func (h *HugoSites) loadGitInfo() error {
if h.Cfg.GetBool("enableGitInfo") {
gi, err := newGitInfo(h.Cfg)
if err != nil {
- h.Log.ERROR.Println("Failed to read Git log:", err)
+ h.Log.Errorln("Failed to read Git log:", err)
} else {
h.gitInfo = gi
}
@@ -570,7 +570,7 @@ func (h *HugoSites) resetLogs() {
h.Log.Reset()
loggers.GlobalErrorCounter.Reset()
for _, s := range h.Sites {
- s.Deps.DistinctErrorLog = helpers.NewDistinctLogger(h.Log.ERROR)
+ s.Deps.DistinctErrorLog = helpers.NewDistinctLogger(h.Log.Error())
}
}
@@ -879,14 +879,14 @@ func (h *HugoSites) handleDataFile(r source.File) error {
// 1. A theme uses the same key; the main data folder wins
// 2. A sub folder uses the same key: the sub folder wins
// TODO(bep) figure out a way to detect 2) above and make that a WARN
- h.Log.INFO.Printf("Data for key '%s' in path '%s' is overridden by higher precedence data already in the data tree", key, r.Path())
+ h.Log.Infof("Data for key '%s' in path '%s' is overridden by higher precedence data already in the data tree", key, r.Path())
} else {
higherPrecedentMap[key] = value
}
}
default:
// can't merge: higherPrecedentData is not a map
- h.Log.WARN.Printf("The %T data from '%s' overridden by "+
+ h.Log.Warnf("The %T data from '%s' overridden by "+
"higher precedence %T data already in the data tree", data, r.Path(), higherPrecedentData)
}
@@ -895,12 +895,12 @@ func (h *HugoSites) handleDataFile(r source.File) error {
current[r.BaseFileName()] = data
} else {
// we don't merge array data
- h.Log.WARN.Printf("The %T data from '%s' overridden by "+
+ h.Log.Warnf("The %T data from '%s' overridden by "+
"higher precedence %T data already in the data tree", data, r.Path(), higherPrecedentData)
}
default:
- h.Log.ERROR.Printf("unexpected data type %T in file %s", data, r.LogicalName())
+ h.Log.Errorf("unexpected data type %T in file %s", data, r.LogicalName())
}
return nil
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index 67ee10e09..3c0440a97 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -162,9 +162,8 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
var b bytes.Buffer
h.Metrics.WriteMetrics(&b)
- h.Log.FEEDBACK.Printf("\nTemplate Metrics:\n\n")
- h.Log.FEEDBACK.Print(b.String())
- h.Log.FEEDBACK.Println()
+ h.Log.Printf("\nTemplate Metrics:\n\n")
+ h.Log.Println(b.String())
}
select {
@@ -183,7 +182,7 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
return err
}
- errorCount := h.Log.ErrorCounter.Count()
+ errorCount := h.Log.LogCounters().ErrorCounter.Count()
if errorCount > 0 {
return fmt.Errorf("logged %d error(s)", errorCount)
}
diff --git a/hugolib/page.go b/hugolib/page.go
index ca93bf18b..859834b91 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -536,7 +536,7 @@ func (p *pageState) renderResources() (err error) {
// mode when the same resource is member of different page bundles.
toBeDeleted = append(toBeDeleted, i)
} else {
- p.s.Log.ERROR.Printf("Failed to publish Resource for page %q: %s", p.pathOrTitle(), err)
+ p.s.Log.Errorf("Failed to publish Resource for page %q: %s", p.pathOrTitle(), err)
}
} else {
p.s.PathSpec.ProcessingStats.Incr(&p.s.PathSpec.ProcessingStats.Files)
@@ -718,7 +718,7 @@ func (p *pageState) getContentConverter() converter.Converter {
})
if err != nil {
- p.s.Log.ERROR.Println("Failed to create content converter:", err)
+ p.s.Log.Errorln("Failed to create content converter:", err)
}
return p.m.contentConverter
}
diff --git a/hugolib/page__menus.go b/hugolib/page__menus.go
index 2b7998afa..7b0ef0e43 100644
--- a/hugolib/page__menus.go
+++ b/hugolib/page__menus.go
@@ -66,7 +66,7 @@ func (p *pageMenus) init() {
var err error
p.pm, err = navigation.PageMenusFromPage(p.p)
if err != nil {
- p.p.s.Log.ERROR.Println(p.p.wrapError(err))
+ p.p.s.Log.Errorln(p.p.wrapError(err))
}
})
diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go
index 631d4233b..52ffbb880 100644
--- a/hugolib/page__meta.go
+++ b/hugolib/page__meta.go
@@ -431,7 +431,7 @@ func (pm *pageMeta) setMetadata(parentBucket *pagesMapBucket, p *pageState, fron
// more easily tested without the Page, but the coupling is strong.
err := pm.s.frontmatterHandler.HandleDates(descriptor)
if err != nil {
- p.s.Log.ERROR.Printf("Failed to handle dates for page %q: %s", p.pathOrTitle(), err)
+ p.s.Log.Errorf("Failed to handle dates for page %q: %s", p.pathOrTitle(), err)
}
pm.buildConfig, err = pagemeta.DecodeBuildConfig(frontmatter["_build"])
@@ -486,7 +486,7 @@ func (pm *pageMeta) setMetadata(parentBucket *pagesMapBucket, p *pageState, fron
// We added support for page relative URLs in Hugo 0.55 and
// this may get its language path added twice.
// TODO(bep) eventually remove this.
- p.s.Log.WARN.Printf(`Front matter in %q with the url %q with no leading / has what looks like the language prefix added. In Hugo 0.55 we added support for page relative URLs in front matter, no language prefix needed. Check the URL and consider to either add a leading / or remove the language prefix.`, p.pathOrTitle(), url)
+ p.s.Log.Warnf(`Front matter in %q with the url %q with no leading / has what looks like the language prefix added. In Hugo 0.55 we added support for page relative URLs in front matter, no language prefix needed. Check the URL and consider to either add a leading / or remove the language prefix.`, p.pathOrTitle(), url)
}
}
@@ -515,7 +515,7 @@ func (pm *pageMeta) setMetadata(parentBucket *pagesMapBucket, p *pageState, fron
outFormats, err := p.s.outputFormatsConfig.GetByNames(o...)
if err != nil {
- p.s.Log.ERROR.Printf("Failed to resolve output formats: %s", err)
+ p.s.Log.Errorf("Failed to resolve output formats: %s", err)
} else {
pm.configuredOutputFormats = outFormats
pm.params[loki] = outFormats
@@ -634,7 +634,7 @@ func (pm *pageMeta) setMetadata(parentBucket *pagesMapBucket, p *pageState, fron
if draft != nil && published != nil {
pm.draft = *draft
- p.m.s.Log.WARN.Printf("page %q has both draft and published settings in its frontmatter. Using draft.", p.File().Filename())
+ p.m.s.Log.Warnf("page %q has both draft and published settings in its frontmatter. Using draft.", p.File().Filename())
} else if draft != nil {
pm.draft = *draft
} else if published != nil {
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 9e58cc66a..aceeaeb36 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -91,7 +91,7 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
// See https://github.com/gohugoio/hugo/issues/6210
if r := recover(); r != nil {
err = fmt.Errorf("%s", r)
- p.s.Log.ERROR.Printf("[BUG] Got panic:\n%s\n%s", r, string(debug.Stack()))
+ p.s.Log.Errorf("[BUG] Got panic:\n%s\n%s", r, string(debug.Stack()))
}
}()
@@ -177,7 +177,7 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
} else {
summary, content, err := splitUserDefinedSummaryAndContent(cp.p.m.markup, cp.workContent)
if err != nil {
- cp.p.s.Log.ERROR.Printf("Failed to set user defined summary for page %q: %s", cp.p.pathOrTitle(), err)
+ cp.p.s.Log.Errorf("Failed to set user defined summary for page %q: %s", cp.p.pathOrTitle(), err)
} else {
cp.workContent = content
cp.summary = helpers.BytesToHTML(summary)
diff --git a/hugolib/pages_capture.go b/hugolib/pages_capture.go
index 4ee33992d..9f2e4bab1 100644
--- a/hugolib/pages_capture.go
+++ b/hugolib/pages_capture.go
@@ -41,7 +41,7 @@ const (
func newPagesCollector(
sp *source.SourceSpec,
contentMap *pageMaps,
- logger *loggers.Logger,
+ logger loggers.Logger,
contentTracker *contentChangeMap,
proc pagesCollectorProcessorProvider, filenames ...string) *pagesCollector {
@@ -83,7 +83,7 @@ type pageBundles map[string]*fileinfoBundle
type pagesCollector struct {
sp *source.SourceSpec
fs afero.Fs
- logger *loggers.Logger
+ logger loggers.Logger
contentMap *pageMaps
@@ -441,7 +441,7 @@ func (c *pagesCollector) collectDir(dirname string, partial bool, inFilter func(
// The branch variant will win because of sort order, but log
// a warning about it.
if thisBtype > bundleNot && btype > bundleNot && thisBtype != btype {
- c.logger.WARN.Printf("Content directory %q have both index.* and _index.* files, pick one.", dir.Meta().Filename())
+ c.logger.Warnf("Content directory %q have both index.* and _index.* files, pick one.", dir.Meta().Filename())
// Reclassify it so it will be handled as a content file inside the
// section, which is in line with the <= 0.55 behaviour.
meta["classifier"] = files.ContentClassContent
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 366c9971c..619047e38 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -324,7 +324,7 @@ func renderShortcode(
var found, more bool
tmpl, found, more = s.Tmpl().LookupVariant(sc.name, tplVariants)
if !found {
- s.Log.ERROR.Printf("Unable to locate template for shortcode %q in page %q", sc.name, p.File().Path())
+ s.Log.Errorf("Unable to locate template for shortcode %q in page %q", sc.name, p.File().Path())
return "", false, nil
}
hasVariants = hasVariants || more
@@ -349,7 +349,7 @@ func renderShortcode(
hasVariants = hasVariants || more
inner += s
default:
- s.Log.ERROR.Printf("Illegal state on shortcode rendering of %q in page %q. Illegal type in inner data: %s ",
+ s.Log.Errorf("Illegal state on shortcode rendering of %q in page %q. Illegal type in inner data: %s ",
sc.name, p.File().Path(), reflect.TypeOf(innerData))
return "", false, nil
}
diff --git a/hugolib/site.go b/hugolib/site.go
index 43fbbe50e..ec2939530 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -425,7 +425,7 @@ func newSite(cfg deps.DepsCfg) (*Site, error) {
delete(disabledKinds, "taxonomyTerm")
} else if disabledKinds[page.KindTaxonomy] && !disabledKinds[page.KindTerm] {
// This is a potentially ambigous situation. It may be correct.
- ignorableLogger.Errorf(constants.ErrIDAmbigousDisableKindTaxonomy, `You have the value 'taxonomy' in the disabledKinds list. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term).
+ ignorableLogger.Errorsf(constants.ErrIDAmbigousDisableKindTaxonomy, `You have the value 'taxonomy' in the disabledKinds list. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term).
But this also means that your site configuration may not do what you expect. If it is correct, you can suppress this message by following the instructions below.`)
}
@@ -485,7 +485,7 @@ But this also means that your site configuration may not do what you expect. If
delete(siteOutputs, "taxonomyTerm")
} else if hasTaxonomy && !hasTerm {
// This is a potentially ambigous situation. It may be correct.
- ignorableLogger.Errorf(constants.ErrIDAmbigousOutputKindTaxonomy, `You have configured output formats for 'taxonomy' in your site configuration. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term).
+ ignorableLogger.Errorsf(constants.ErrIDAmbigousOutputKindTaxonomy, `You have configured output formats for 'taxonomy' in your site configuration. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term).
But this also means that your site configuration may not do what you expect. If it is correct, you can suppress this message by following the instructions below.`)
}
if !hasTaxonomy && hasTaxonomyTerm {
@@ -806,12 +806,12 @@ type siteRefLinker struct {
}
func newSiteRefLinker(cfg config.Provider, s *Site) (siteRefLinker, error) {
- logger := s.Log.ERROR
+ logger := s.Log.Error()
notFoundURL := cfg.GetString("refLinksNotFoundURL")
errLevel := cfg.GetString("refLinksErrorLevel")
if strings.EqualFold(errLevel, "warning") {
- logger = s.Log.WARN
+ logger = s.Log.Warn()
}
return siteRefLinker{s: s, errorLogger: logger, notFoundURL: notFoundURL}, nil
}
@@ -1006,7 +1006,7 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro
changeIdentities := make(identity.Identities)
- s.Log.DEBUG.Printf("Rebuild for events %q", events)
+ s.Log.Debug().Printf("Rebuild for events %q", events)
h := s.h
@@ -1377,17 +1377,17 @@ func (s *Site) getMenusFromConfig() navigation.Menus {
for name, menu := range menus {
m, err := cast.ToSliceE(menu)
if err != nil {
- s.Log.ERROR.Printf("unable to process menus in site config\n")
- s.Log.ERROR.Println(err)
+ s.Log.Errorf("unable to process menus in site config\n")
+ s.Log.Errorln(err)
} else {
for _, entry := range m {
- s.Log.DEBUG.Printf("found menu: %q, in site config\n", name)
+ s.Log.Debug().Printf("found menu: %q, in site config\n", name)
menuEntry := navigation.MenuEntry{Menu: name}
ime, err := maps.ToStringMapE(entry)
if err != nil {
- s.Log.ERROR.Printf("unable to process menus in site config\n")
- s.Log.ERROR.Println(err)
+ s.Log.Errorf("unable to process menus in site config\n")
+ s.Log.Errorln(err)
}
menuEntry.MarshallMap(ime)
@@ -1471,7 +1471,7 @@ func (s *Site) assembleMenus() {
for name, me := range p.pageMenus.menus() {
if _, ok := flat[twoD{name, me.KeyName()}]; ok {
err := p.wrapError(errors.Errorf("duplicate menu entry with identifier %q in menu %q", me.KeyName(), name))
- s.Log.WARN.Println(err)
+ s.Log.Warnln(err)
continue
}
flat[twoD{name, me.KeyName()}] = me
@@ -1643,7 +1643,7 @@ func (s *Site) lookupLayouts(layouts ...string) tpl.Template {
}
func (s *Site) renderAndWriteXML(statCounter *uint64, name string, targetPath string, d interface{}, templ tpl.Template) error {
- s.Log.DEBUG.Printf("Render XML for %q to %q", name, targetPath)
+ s.Log.Debug().Printf("Render XML for %q to %q", name, targetPath)
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
@@ -1665,7 +1665,7 @@ func (s *Site) renderAndWriteXML(statCounter *uint64, name string, targetPath st
}
func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath string, p *pageState, templ tpl.Template) error {
- s.Log.DEBUG.Printf("Render %s to %q", name, targetPath)
+ s.Log.Debug().Printf("Render %s to %q", name, targetPath)
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
index 7f5bcfb1a..531d481f0 100644
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -149,9 +149,9 @@ func pageRenderer(
}
func (s *Site) logMissingLayout(name, layout, kind, outputFormat string) {
- log := s.Log.WARN
+ log := s.Log.Warn()
if name != "" && infoOnMissingLayout[name] {
- log = s.Log.INFO
+ log = s.Log.Info()
}
errMsg := "You should create a template file which matches Hugo Layouts Lookup Rules for this combination."
@@ -396,13 +396,13 @@ func (s *Site) renderMainLanguageRedirect() error {
mainLang := s.h.multilingual.DefaultLang
if s.Info.defaultContentLanguageInSubdir {
mainLangURL := s.PathSpec.AbsURL(mainLang.Lang+"/", false)
- s.Log.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
+ s.Log.Debug().Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
if err := s.publishDestAlias(true, "/", mainLangURL, html, nil); err != nil {
return err
}
} else {
mainLangURL := s.PathSpec.AbsURL("", false)
- s.Log.DEBUG.Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
+ s.Log.Debug().Printf("Write redirect to main language %s: %s", mainLang, mainLangURL)
if err := s.publishDestAlias(true, mainLang.Lang, mainLangURL, html, nil); err != nil {
return err
}
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go
index 2af4691d1..5b825cd1e 100644
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -67,7 +67,7 @@ type sitesBuilder struct {
*qt.C
- logger *loggers.Logger
+ logger loggers.Logger
rnd *rand.Rand
dumper litter.Options
@@ -154,7 +154,7 @@ func (s *sitesBuilder) WithNothingAdded() *sitesBuilder {
return s
}
-func (s *sitesBuilder) WithLogger(logger *loggers.Logger) *sitesBuilder {
+func (s *sitesBuilder) WithLogger(logger loggers.Logger) *sitesBuilder {
s.logger = logger
return s
}
diff --git a/langs/i18n/i18n.go b/langs/i18n/i18n.go
index c0eac5837..31cb5d732 100644
--- a/langs/i18n/i18n.go
+++ b/langs/i18n/i18n.go
@@ -35,11 +35,11 @@ var (
type Translator struct {
translateFuncs map[string]translateFunc
cfg config.Provider
- logger *loggers.Logger
+ logger loggers.Logger
}
// NewTranslator creates a new Translator for the given language bundle and configuration.
-func NewTranslator(b *i18n.Bundle, cfg config.Provider, logger *loggers.Logger) Translator {
+func NewTranslator(b *i18n.Bundle, cfg config.Provider, logger loggers.Logger) Translator {
t := Translator{cfg: cfg, logger: logger, translateFuncs: make(map[string]translateFunc)}
t.initFuncs(b)
return t
@@ -51,12 +51,12 @@ func (t Translator) Func(lang string) translateFunc {
if f, ok := t.translateFuncs[lang]; ok {
return f
}
- t.logger.INFO.Printf("Translation func for language %v not found, use default.", lang)
+ t.logger.Infof("Translation func for language %v not found, use default.", lang)
if f, ok := t.translateFuncs[t.cfg.GetString("defaultContentLanguage")]; ok {
return f
}
- t.logger.INFO.Println("i18n not initialized; if you need string translations, check that you have a bundle in /i18n that matches the site language or the default language.")
+ t.logger.Infoln("i18n not initialized; if you need string translations, check that you have a bundle in /i18n that matches the site language or the default language.")
return func(translationID string, args interface{}) string {
return ""
}
@@ -98,7 +98,7 @@ func (t Translator) initFuncs(bndl *i18n.Bundle) {
}
if _, ok := err.(*i18n.MessageNotFoundErr); !ok {
- t.logger.WARN.Printf("Failed to get translated string for language %q and ID %q: %s", currentLangStr, translationID, err)
+ t.logger.Warnf("Failed to get translated string for language %q and ID %q: %s", currentLangStr, translationID, err)
}
if t.cfg.GetBool("logI18nWarnings") {
diff --git a/markup/asciidocext/convert.go b/markup/asciidocext/convert.go
index f3e451496..a92b6f9e3 100644
--- a/markup/asciidocext/convert.go
+++ b/markup/asciidocext/convert.go
@@ -82,7 +82,7 @@ func (a *asciidocConverter) Supports(_ identity.Identity) bool {
func (a *asciidocConverter) getAsciidocContent(src []byte, ctx converter.DocumentContext) []byte {
path := getAsciidoctorExecPath()
if path == "" {
- a.cfg.Logger.ERROR.Println("asciidoctor not found in $PATH: Please install.\n",
+ a.cfg.Logger.Errorln("asciidoctor not found in $PATH: Please install.\n",
" Leaving AsciiDoc content unrendered.")
return src
}
@@ -90,7 +90,7 @@ func (a *asciidocConverter) getAsciidocContent(src []byte, ctx converter.Documen
args := a.parseArgs(ctx)
args = append(args, "-")
- a.cfg.Logger.INFO.Println("Rendering", ctx.DocumentName, "with", path, "using asciidoctor args", args, "...")
+ a.cfg.Logger.Infoln("Rendering", ctx.DocumentName, "with", path, "using asciidoctor args", args, "...")
return internal.ExternallyRenderContent(a.cfg, ctx, src, path, args)
}
@@ -103,7 +103,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
for _, extension := range cfg.Extensions {
if !asciidocext_config.AllowedExtensions[extension] {
- a.cfg.Logger.ERROR.Println("Unsupported asciidoctor extension was passed in. Extension `" + extension + "` ignored.")
+ a.cfg.Logger.Errorln("Unsupported asciidoctor extension was passed in. Extension `" + extension + "` ignored.")
continue
}
@@ -112,7 +112,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
for attributeKey, attributeValue := range cfg.Attributes {
if asciidocext_config.DisallowedAttributes[attributeKey] {
- a.cfg.Logger.ERROR.Println("Unsupported asciidoctor attribute was passed in. Attribute `" + attributeKey + "` ignored.")
+ a.cfg.Logger.Errorln("Unsupported asciidoctor attribute was passed in. Attribute `" + attributeKey + "` ignored.")
continue
}
@@ -125,7 +125,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
destinationDir := a.cfg.Cfg.GetString("destination")
if destinationDir == "" {
- a.cfg.Logger.ERROR.Println("markup.asciidocext.workingFolderCurrent requires hugo command option --destination to be set")
+ a.cfg.Logger.Errorln("markup.asciidocext.workingFolderCurrent requires hugo command option --destination to be set")
}
if !filepath.IsAbs(destinationDir) && sourceDir != "" {
destinationDir = filepath.Join(sourceDir, destinationDir)
@@ -144,14 +144,14 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
if ok {
postDir = filepath.Base(page.RelPermalink())
} else {
- a.cfg.Logger.ERROR.Println("unable to cast interface to pageSubset")
+ a.cfg.Logger.Errorln("unable to cast interface to pageSubset")
}
outDir, err = filepath.Abs(filepath.Join(destinationDir, filepath.Dir(ctx.DocumentName), postDir))
}
if err != nil {
- a.cfg.Logger.ERROR.Println("asciidoctor outDir: ", err)
+ a.cfg.Logger.Errorln("asciidoctor outDir: ", err)
}
args = append(args, "--base-dir", contentDir, "-a", "outdir="+outDir)
@@ -160,7 +160,7 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
if cfg.NoHeaderOrFooter {
args = append(args, "--no-header-footer")
} else {
- a.cfg.Logger.WARN.Println("asciidoctor parameter NoHeaderOrFooter is expected for correct html rendering")
+ a.cfg.Logger.Warnln("asciidoctor parameter NoHeaderOrFooter is expected for correct html rendering")
}
if cfg.SectionNumbers {
@@ -187,7 +187,7 @@ func (a *asciidocConverter) appendArg(args []string, option, value, defaultValue
if allowedValues[value] {
args = append(args, option, value)
} else {
- a.cfg.Logger.ERROR.Println("Unsupported asciidoctor value `" + value + "` for option " + option + " was passed in and will be ignored.")
+ a.cfg.Logger.Errorln("Unsupported asciidoctor value `" + value + "` for option " + option + " was passed in and will be ignored.")
}
}
return args
diff --git a/markup/converter/converter.go b/markup/converter/converter.go
index 63434e045..231527441 100644
--- a/markup/converter/converter.go
+++ b/markup/converter/converter.go
@@ -31,7 +31,7 @@ type ProviderConfig struct {
Cfg config.Provider // Site config
ContentFs afero.Fs
- Logger *loggers.Logger
+ Logger loggers.Logger
Highlight func(code, lang, optsStr string) (string, error)
}
diff --git a/markup/internal/external.go b/markup/internal/external.go
index 2105e7cff..fc7fddb23 100644
--- a/markup/internal/external.go
+++ b/markup/internal/external.go
@@ -25,11 +25,11 @@ func ExternallyRenderContent(
for _, item := range strings.Split(cmderr.String(), "\n") {
item := strings.TrimSpace(item)
if item != "" {
- logger.ERROR.Printf("%s: %s", ctx.DocumentName, item)
+ logger.Errorf("%s: %s", ctx.DocumentName, item)
}
}
if err != nil {
- logger.ERROR.Printf("%s rendering %s: %v", path, ctx.DocumentName, err)
+ logger.Errorf("%s rendering %s: %v", path, ctx.DocumentName, err)
}
return normalizeExternalHelperLineFeeds(out.Bytes())
diff --git a/markup/org/convert.go b/markup/org/convert.go
index 7a3ad7076..34043e18d 100644
--- a/markup/org/convert.go
+++ b/markup/org/convert.go
@@ -47,7 +47,7 @@ type orgConverter struct {
func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.Result, error) {
logger := c.cfg.Logger
config := org.New()
- config.Log = logger.WARN
+ config.Log = logger.Warn()
config.ReadFile = func(filename string) ([]byte, error) {
return afero.ReadFile(c.cfg.ContentFs, filename)
}
@@ -55,7 +55,7 @@ func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.Result, e
writer.HighlightCodeBlock = func(source, lang string, inline bool) string {
highlightedSource, err := c.cfg.Highlight(source, lang, "")
if err != nil {
- logger.ERROR.Printf("Could not highlight source as lang %s. Using raw source.", lang)
+ logger.Errorf("Could not highlight source as lang %s. Using raw source.", lang)
return source
}
return highlightedSource
@@ -63,7 +63,7 @@ func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.Result, e
html, err := config.Parse(bytes.NewReader(ctx.Src), c.ctx.DocumentName).Write(writer)
if err != nil {
- logger.ERROR.Printf("Could not render org: %s. Using unrendered content.", err)
+ logger.Errorf("Could not render org: %s. Using unrendered content.", err)
return converter.Bytes(ctx.Src), nil
}
return converter.Bytes([]byte(html)), nil
diff --git a/markup/pandoc/convert.go b/markup/pandoc/convert.go
index d6d5ab18c..074e97d96 100644
--- a/markup/pandoc/convert.go
+++ b/markup/pandoc/convert.go
@@ -57,7 +57,7 @@ func (c *pandocConverter) getPandocContent(src []byte, ctx converter.DocumentCon
logger := c.cfg.Logger
path := getPandocExecPath()
if path == "" {
- logger.ERROR.Println("pandoc not found in $PATH: Please install.\n",
+ logger.Println("pandoc not found in $PATH: Please install.\n",
" Leaving pandoc content unrendered.")
return src
}
diff --git a/markup/rst/convert.go b/markup/rst/convert.go
index 64cc8b511..cbc15c81a 100644
--- a/markup/rst/convert.go
+++ b/markup/rst/convert.go
@@ -60,11 +60,11 @@ func (c *rstConverter) getRstContent(src []byte, ctx converter.DocumentContext)
path := getRstExecPath()
if path == "" {
- logger.ERROR.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
+ logger.Println("rst2html / rst2html.py not found in $PATH: Please install.\n",
" Leaving reStructuredText content unrendered.")
return src
}
- logger.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
+ logger.Println("Rendering", ctx.DocumentName, "with", path, "...")
var result []byte
// certain *nix based OSs wrap executables in scripted launchers
// invoking binaries on these OSs via python interpreter causes SyntaxError
diff --git a/modules/client.go b/modules/client.go
index d71c48f0c..d07483d36 100644
--- a/modules/client.go
+++ b/modules/client.go
@@ -119,7 +119,7 @@ func NewClient(cfg ClientConfig) *Client {
// Client contains most of the API provided by this package.
type Client struct {
fs afero.Fs
- logger *loggers.Logger
+ logger loggers.Logger
noVendor glob.Glob
@@ -329,7 +329,7 @@ func (c *Client) Get(args ...string) error {
}
func (c *Client) get(args ...string) error {
- if err := c.runGo(context.Background(), c.logger.Out, append([]string{"get"}, args...)...); err != nil {
+ if err := c.runGo(context.Background(), c.logger.Out(), append([]string{"get"}, args...)...); err != nil {
errors.Wrapf(err, "failed to get %q", args)
}
return nil
@@ -339,7 +339,7 @@ func (c *Client) get(args ...string) error {
// If path is empty, Go will try to guess.
// If this succeeds, this project will be marked as Go Module.
func (c *Client) Init(path string) error {
- err := c.runGo(context.Background(), c.logger.Out, "mod", "init", path)
+ err := c.runGo(context.Background(), c.logger.Out(), "mod", "init", path)
if err != nil {
return errors.Wrap(err, "failed to init modules")
}
@@ -403,7 +403,7 @@ func (c *Client) Clean(pattern string) error {
}
_, err = hugofs.MakeReadableAndRemoveAllModulePkgDir(c.fs, m.Dir)
if err == nil {
- c.logger.FEEDBACK.Printf("hugo: cleaned module cache for %q", m.Path)
+ c.logger.Printf("hugo: cleaned module cache for %q", m.Path)
}
}
return err
@@ -560,7 +560,7 @@ func (c *Client) runGo(
if strings.Contains(stderr.String(), "invalid version: unknown revision") {
// See https://github.com/gohugoio/hugo/issues/6825
- c.logger.FEEDBACK.Println(`hugo: you need to manually edit go.mod to resolve the unknown revision.`)
+ c.logger.Println(`hugo: you need to manually edit go.mod to resolve the unknown revision.`)
}
_, ok := err.(*exec.ExitError)
@@ -616,7 +616,7 @@ func (c *Client) shouldVendor(path string) bool {
// ClientConfig configures the module Client.
type ClientConfig struct {
Fs afero.Fs
- Logger *loggers.Logger
+ Logger loggers.Logger
// If set, it will be run before we do any duplicate checks for modules
// etc.
diff --git a/modules/collect.go b/modules/collect.go
index 8959572d6..3059d3f99 100644
--- a/modules/collect.go
+++ b/modules/collect.go
@@ -124,11 +124,11 @@ type ModulesConfig struct {
GoModulesFilename string
}
-func (m *ModulesConfig) setActiveMods(logger *loggers.Logger) error {
+func (m *ModulesConfig) setActiveMods(logger loggers.Logger) error {
var activeMods Modules
for _, mod := range m.AllModules {
if !mod.Config().HugoVersion.IsValid() {
- logger.WARN.Printf(`Module %q is not compatible with this Hugo version; run "hugo mod graph" for more information.`, mod.Path())
+ logger.Warnf(`Module %q is not compatible with this Hugo version; run "hugo mod graph" for more information.`, mod.Path())
}
if !mod.Disabled() {
activeMods = append(activeMods, mod)
@@ -140,7 +140,7 @@ func (m *ModulesConfig) setActiveMods(logger *loggers.Logger) error {
return nil
}
-func (m *ModulesConfig) finalize(logger *loggers.Logger) error {
+func (m *ModulesConfig) finalize(logger loggers.Logger) error {
for _, mod := range m.AllModules {
m := mod.(*moduleAdapter)
m.mounts = filterUnwantedMounts(m.mounts)
@@ -422,7 +422,7 @@ func (c *collector) applyThemeConfig(tc *moduleAdapter) error {
}
themeCfg, err = metadecoders.Default.UnmarshalToMap(data, metadecoders.TOML)
if err != nil {
- c.logger.WARN.Printf("Failed to read module config for %q in %q: %s", tc.Path(), themeTOML, err)
+ c.logger.Warnf("Failed to read module config for %q in %q: %s", tc.Path(), themeTOML, err)
} else {
maps.ToLower(themeCfg)
}
@@ -480,7 +480,7 @@ func (c *collector) collect() {
defer c.logger.PrintTimerIfDelayed(time.Now(), "hugo: collected modules")
d := debounce.New(2 * time.Second)
d(func() {
- c.logger.FEEDBACK.Println("hugo: downloading modules …")
+ c.logger.Println("hugo: downloading modules …")
})
defer d(func() {})
diff --git a/resources/page/pagemeta/page_frontmatter.go b/resources/page/pagemeta/page_frontmatter.go
index 7b9f13e62..5033d70b7 100644
--- a/resources/page/pagemeta/page_frontmatter.go
+++ b/resources/page/pagemeta/page_frontmatter.go
@@ -38,7 +38,7 @@ type FrontMatterHandler struct {
// A map of all date keys configured, including any custom.
allDateKeys map[string]bool
- logger *loggers.Logger
+ logger loggers.Logger
}
// FrontMatterDescriptor describes how to handle front matter for a given Page.
@@ -148,7 +148,7 @@ func (f FrontMatterHandler) newChainedFrontMatterFieldHandler(handlers ...frontM
// First successful handler wins.
success, err := h(d)
if err != nil {
- f.logger.ERROR.Println(err)
+ f.logger.Errorln(err)
} else if success {
return true, nil
}
@@ -262,7 +262,7 @@ func toLowerSlice(in interface{}) []string {
// NewFrontmatterHandler creates a new FrontMatterHandler with the given logger and configuration.
// If no logger is provided, one will be created.
-func NewFrontmatterHandler(logger *loggers.Logger, cfg config.Provider) (FrontMatterHandler, error) {
+func NewFrontmatterHandler(logger loggers.Logger, cfg config.Provider) (FrontMatterHandler, error) {
if logger == nil {
logger = loggers.NewErrorLogger()
diff --git a/resources/resource_spec.go b/resources/resource_spec.go
index 81eed2f02..17225e3f5 100644
--- a/resources/resource_spec.go
+++ b/resources/resource_spec.go
@@ -47,7 +47,7 @@ func NewSpec(
s *helpers.PathSpec,
fileCaches filecache.Caches,
incr identity.Incrementer,
- logger *loggers.Logger,
+ logger loggers.Logger,
errorHandler herrors.ErrorSender,
outputFormats output.Formats,
mimeTypes media.Types) (*Spec, error) {
@@ -105,7 +105,7 @@ type Spec struct {
MediaTypes media.Types
OutputFormats output.Formats
- Logger *loggers.Logger
+ Logger loggers.Logger
ErrorSender herrors.ErrorSender
TextTemplates tpl.TemplateParseFinder
diff --git a/resources/resource_transformers/babel/babel.go b/resources/resource_transformers/babel/babel.go
index 4255210c3..a9d39d31b 100644
--- a/resources/resource_transformers/babel/babel.go
+++ b/resources/resource_transformers/babel/babel.go
@@ -121,7 +121,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
logger := t.rs.Logger
var errBuf bytes.Buffer
- infoW := loggers.LoggerToWriterWithPrefix(logger.INFO, "babel")
+ infoW := loggers.LoggerToWriterWithPrefix(logger.Info(), "babel")
if t.options.Config != "" {
configFile = t.options.Config
@@ -143,7 +143,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
var cmdArgs []string
if configFile != "" {
- logger.INFO.Println("babel: use config file", configFile)
+ logger.Infoln("babel: use config file", configFile)
cmdArgs = []string{"--config-file", configFile}
}
diff --git a/resources/resource_transformers/postcss/postcss.go b/resources/resource_transformers/postcss/postcss.go
index 41472fe98..daeb7212a 100644
--- a/resources/resource_transformers/postcss/postcss.go
+++ b/resources/resource_transformers/postcss/postcss.go
@@ -181,7 +181,7 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
var cmdArgs []string
if configFile != "" {
- logger.INFO.Println("postcss: use config file", configFile)
+ logger.Infoln("postcss: use config file", configFile)
cmdArgs = []string{"--config", configFile}
}
@@ -192,7 +192,7 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
cmd := exec.Command(binary, cmdArgs...)
var errBuf bytes.Buffer
- infoW := loggers.LoggerToWriterWithPrefix(logger.INFO, "postcss")
+ infoW := loggers.LoggerToWriterWithPrefix(logger.Info(), "postcss")
cmd.Stdout = ctx.To
cmd.Stderr = io.MultiWriter(infoW, &errBuf)
@@ -245,10 +245,10 @@ type importResolver struct {
contentSeen map[string]bool
linemap map[int]fileOffset
fs afero.Fs
- logger *loggers.Logger
+ logger loggers.Logger
}
-func newImportResolver(r io.Reader, inPath string, fs afero.Fs, logger *loggers.Logger) *importResolver {
+func newImportResolver(r io.Reader, inPath string, fs afero.Fs, logger loggers.Logger) *importResolver {
return &importResolver{
r: r,
inPath: inPath,
@@ -296,7 +296,7 @@ func (imp *importResolver) importRecursive(
importContent, hash := imp.contentHash(filename)
if importContent == nil {
trackLine(i, offset, "ERROR")
- imp.logger.WARN.Printf("postcss: Failed to resolve CSS @import in %q for path %q", inPath, filename)
+ imp.logger.Warnf("postcss: Failed to resolve CSS @import in %q for path %q", inPath, filename)
continue
}
diff --git a/resources/transform.go b/resources/transform.go
index 7793d3e0e..354a20eec 100644
--- a/resources/transform.go
+++ b/resources/transform.go
@@ -290,7 +290,7 @@ func (r *resourceAdapter) publish() {
r.publisherErr = r.target.Publish()
if r.publisherErr != nil {
- r.spec.Logger.ERROR.Printf("Failed to publish Resource: %s", r.publisherErr)
+ r.spec.Logger.Errorf("Failed to publish Resource: %s", r.publisherErr)
}
})
@@ -546,7 +546,7 @@ func (r *resourceAdapter) initTransform(publish, setContent bool) {
if r.spec.ErrorSender != nil {
r.spec.ErrorSender.SendError(r.transformationsErr)
} else {
- r.spec.Logger.ERROR.Printf("Transformation failed: %s", r.transformationsErr)
+ r.spec.Logger.Errorf("Transformation failed: %s", r.transformationsErr)
}
}
})
diff --git a/tpl/data/data.go b/tpl/data/data.go
index f64ba0127..964844336 100644
--- a/tpl/data/data.go
+++ b/tpl/data/data.go
@@ -23,6 +23,9 @@ import (
"net/http"
"strings"
+ "github.com/gohugoio/hugo/common/constants"
+ "github.com/gohugoio/hugo/common/loggers"
+
"github.com/spf13/cast"
"github.com/gohugoio/hugo/cache/filecache"
@@ -85,7 +88,7 @@ func (ns *Namespace) GetCSV(sep string, urlParts ...interface{}) (d [][]string,
err = ns.getResource(cache, unmarshal, req)
if err != nil {
- ns.deps.Log.ERROR.Printf("Failed to get CSV resource %q: %s", url, err)
+ ns.deps.Log.(loggers.IgnorableLogger).Errorsf(constants.ErrRemoteGetCSV, "Failed to get CSV resource %q: %s", url, err)
return nil, nil
}
@@ -117,7 +120,7 @@ func (ns *Namespace) GetJSON(urlParts ...interface{}) (interface{}, error) {
err = ns.getResource(cache, unmarshal, req)
if err != nil {
- ns.deps.Log.ERROR.Printf("Failed to get JSON resource %q: %s", url, err)
+ ns.deps.Log.(loggers.IgnorableLogger).Errorsf(constants.ErrRemoteGetJSON, "Failed to get JSON resource %q: %s", url, err)
return nil, nil
}
diff --git a/tpl/data/data_test.go b/tpl/data/data_test.go
index fa99006b2..e1839dd48 100644
--- a/tpl/data/data_test.go
+++ b/tpl/data/data_test.go
@@ -108,14 +108,14 @@ func TestGetCSV(t *testing.T) {
got, err := ns.GetCSV(test.sep, test.url)
if _, ok := test.expect.(bool); ok {
- c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 1)
+ c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 1)
//c.Assert(err, msg, qt.Not(qt.IsNil))
c.Assert(got, qt.IsNil)
continue
}
c.Assert(err, qt.IsNil, msg)
- c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 0)
+ c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 0)
c.Assert(got, qt.Not(qt.IsNil), msg)
c.Assert(got, qt.DeepEquals, test.expect, msg)
@@ -198,12 +198,12 @@ func TestGetJSON(t *testing.T) {
got, _ := ns.GetJSON(test.url)
if _, ok := test.expect.(bool); ok {
- c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 1)
+ c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 1)
//c.Assert(err, msg, qt.Not(qt.IsNil))
continue
}
- c.Assert(int(ns.deps.Log.ErrorCounter.Count()), qt.Equals, 0, msg)
+ c.Assert(int(ns.deps.Log.LogCounters().ErrorCounter.Count()), qt.Equals, 0, msg)
c.Assert(got, qt.Not(qt.IsNil), msg)
c.Assert(got, qt.DeepEquals, test.expect)
}
diff --git a/tpl/data/resources.go b/tpl/data/resources.go
index 923d5946e..a7b8b3f49 100644
--- a/tpl/data/resources.go
+++ b/tpl/data/resources.go
@@ -45,7 +45,7 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (b
var err error
handled = true
for i := 0; i <= resRetries; i++ {
- ns.deps.Log.INFO.Printf("Downloading: %s ...", url)
+ ns.deps.Log.Infof("Downloading: %s ...", url)
var res *http.Response
res, err = ns.client.Do(req)
if err != nil {
@@ -75,8 +75,8 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (b
return nil, err
}
- ns.deps.Log.INFO.Printf("Cannot read remote resource %s: %s", url, err)
- ns.deps.Log.INFO.Printf("Retry #%d for %s and sleeping for %s", i+1, url, resSleep)
+ ns.deps.Log.Infof("Cannot read remote resource %s: %s", url, err)
+ ns.deps.Log.Infof("Retry #%d for %s and sleeping for %s", i+1, url, resSleep)
time.Sleep(resSleep)
}
diff --git a/tpl/data/resources_test.go b/tpl/data/resources_test.go
index 11a9a8fc4..7350f82f1 100644
--- a/tpl/data/resources_test.go
+++ b/tpl/data/resources_test.go
@@ -195,13 +195,13 @@ func newDeps(cfg config.Provider) *deps.Deps {
}
cfg.Set("allModules", modules.Modules{mod})
- cs, err := helpers.NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs())
+ logger := loggers.NewIgnorableLogger(loggers.NewErrorLogger(), "none")
+ cs, err := helpers.NewContentSpec(cfg, logger, afero.NewMemMapFs())
if err != nil {
panic(err)
}
fs := hugofs.NewMem(cfg)
- logger := loggers.NewErrorLogger()
p, err := helpers.NewPathSpec(fs, cfg, nil)
if err != nil {
@@ -219,7 +219,7 @@ func newDeps(cfg config.Provider) *deps.Deps {
FileCaches: fileCaches,
ContentSpec: cs,
Log: logger,
- DistinctErrorLog: helpers.NewDistinctLogger(logger.ERROR),
+ DistinctErrorLog: helpers.NewDistinctLogger(logger.Error()),
}
}
diff --git a/tpl/fmt/fmt.go b/tpl/fmt/fmt.go
index 924d27a1d..780add0d1 100644
--- a/tpl/fmt/fmt.go
+++ b/tpl/fmt/fmt.go
@@ -24,8 +24,8 @@ import (
// New returns a new instance of the fmt-namespaced template functions.
func New(d *deps.Deps) *Namespace {
ns := &Namespace{
- errorLogger: helpers.NewDistinctLogger(d.Log.ERROR),
- warnLogger: helpers.NewDistinctLogger(d.Log.WARN),
+ errorLogger: helpers.NewDistinctLogger(d.Log.Error()),
+ warnLogger: helpers.NewDistinctLogger(d.Log.Warn()),
}
d.BuildStartListeners.Add(func() {