mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
tpl: Add errorf template function
Add template function that will build a string from the given format string and arguments, then log it to ERROR. This has an intended side-effect of causing the build to fail, when executed. Resolves #3817
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
47fdfd5196
commit
4fc67fe44a
@@ -15,15 +15,17 @@ package fmt
|
||||
|
||||
import (
|
||||
_fmt "fmt"
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
)
|
||||
|
||||
// New returns a new instance of the fmt-namespaced template functions.
|
||||
func New() *Namespace {
|
||||
return &Namespace{}
|
||||
return &Namespace{helpers.NewDistinctErrorLogger()}
|
||||
}
|
||||
|
||||
// Namespace provides template functions for the "fmt" namespace.
|
||||
type Namespace struct {
|
||||
errorLogger *helpers.DistinctLogger
|
||||
}
|
||||
|
||||
// Print returns string representation of the passed arguments.
|
||||
@@ -41,3 +43,8 @@ func (ns *Namespace) Printf(format string, a ...interface{}) string {
|
||||
func (ns *Namespace) Println(a ...interface{}) string {
|
||||
return _fmt.Sprintln(a...)
|
||||
}
|
||||
|
||||
func (ns *Namespace) Errorf(format string, a ...interface{}) string {
|
||||
ns.errorLogger.Printf(format, a...)
|
||||
return _fmt.Sprintf(format, a...)
|
||||
}
|
||||
|
Reference in New Issue
Block a user