diff options
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/collections/collections.go | 2 | ||||
-rw-r--r-- | tpl/data/resources_test.go | 12 | ||||
-rw-r--r-- | tpl/fmt/fmt.go | 25 | ||||
-rw-r--r-- | tpl/fmt/init.go | 7 | ||||
-rw-r--r-- | tpl/fmt/init_test.go | 2 |
5 files changed, 32 insertions, 16 deletions
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index 669e386f8..0a9774aa4 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -380,7 +380,7 @@ func (ns *Namespace) IsSet(a interface{}, key interface{}) (bool, error) { return av.MapIndex(kv).IsValid(), nil } default: - helpers.DistinctFeedbackLog.Printf("WARNING: calling IsSet with unsupported type %q (%T) will always return false.\n", av.Kind(), a) + helpers.DistinctErrorLog.Printf("WARNING: calling IsSet with unsupported type %q (%T) will always return false.\n", av.Kind(), a) } return false, nil diff --git a/tpl/data/resources_test.go b/tpl/data/resources_test.go index 5ad0f0970..18061c052 100644 --- a/tpl/data/resources_test.go +++ b/tpl/data/resources_test.go @@ -213,12 +213,12 @@ func newDeps(cfg config.Provider) *deps.Deps { } return &deps.Deps{ - Cfg: cfg, - Fs: fs, - FileCaches: fileCaches, - ContentSpec: cs, - Log: logger, - DistinctErrorLog: helpers.NewDistinctLogger(logger.Error()), + Cfg: cfg, + Fs: fs, + FileCaches: fileCaches, + ContentSpec: cs, + Log: logger, + LogDistinct: helpers.NewDistinctLogger(logger), } } diff --git a/tpl/fmt/fmt.go b/tpl/fmt/fmt.go index 713088b57..9c16ca656 100644 --- a/tpl/fmt/fmt.go +++ b/tpl/fmt/fmt.go @@ -17,20 +17,22 @@ package fmt import ( _fmt "fmt" + "github.com/gohugoio/hugo/common/loggers" + "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/helpers" ) // New returns a new instance of the fmt-namespaced template functions. func New(d *deps.Deps) *Namespace { + ignorableLogger := d.Log.(loggers.IgnorableLogger) + distinctLogger := helpers.NewDistinctLogger(d.Log) ns := &Namespace{ - errorLogger: helpers.NewDistinctLogger(d.Log.Error()), - warnLogger: helpers.NewDistinctLogger(d.Log.Warn()), + distinctLogger: ignorableLogger.Apply(distinctLogger), } d.BuildStartListeners.Add(func() { - ns.errorLogger.Reset() - ns.warnLogger.Reset() + ns.distinctLogger.Reset() }) return ns @@ -38,8 +40,7 @@ func New(d *deps.Deps) *Namespace { // Namespace provides template functions for the "fmt" namespace. type Namespace struct { - errorLogger *helpers.DistinctLogger - warnLogger *helpers.DistinctLogger + distinctLogger loggers.IgnorableLogger } // Print returns string representation of the passed arguments. @@ -60,13 +61,21 @@ func (ns *Namespace) Println(a ...interface{}) string { // Errorf formats according to a format specifier and logs an ERROR. // It returns an empty string. func (ns *Namespace) Errorf(format string, a ...interface{}) string { - ns.errorLogger.Printf(format, a...) + ns.distinctLogger.Errorf(format, a...) + return "" +} + +// Erroridf formats according to a format specifier and logs an ERROR and +// an information text that the error with the given ID can be suppressed in config. +// It returns an empty string. +func (ns *Namespace) Erroridf(id, format string, a ...interface{}) string { + ns.distinctLogger.Errorsf(id, format, a...) return "" } // Warnf formats according to a format specifier and logs a WARNING. // It returns an empty string. func (ns *Namespace) Warnf(format string, a ...interface{}) string { - ns.warnLogger.Printf(format, a...) + ns.distinctLogger.Warnf(format, a...) return "" } diff --git a/tpl/fmt/init.go b/tpl/fmt/init.go index 6a2c9a856..f322f5117 100644 --- a/tpl/fmt/init.go +++ b/tpl/fmt/init.go @@ -57,6 +57,13 @@ func init() { }, ) + ns.AddMethodMapping(ctx.Erroridf, + []string{"erroridf"}, + [][2]string{ + {`{{ erroridf "my-err-id" "%s." "failed" }}`, ``}, + }, + ) + ns.AddMethodMapping(ctx.Warnf, []string{"warnf"}, [][2]string{ diff --git a/tpl/fmt/init_test.go b/tpl/fmt/init_test.go index edc1dbb5e..8fa3945b8 100644 --- a/tpl/fmt/init_test.go +++ b/tpl/fmt/init_test.go @@ -30,7 +30,7 @@ func TestInit(t *testing.T) { var ns *internal.TemplateFuncsNamespace for _, nsf := range internal.TemplateFuncsNamespaceRegistry { - ns = nsf(&deps.Deps{Log: loggers.NewErrorLogger()}) + ns = nsf(&deps.Deps{Log: loggers.NewIgnorableLogger(loggers.NewErrorLogger())}) if ns.Name == name { found = true break |