mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
@@ -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 ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user