forked from gohugoio/hugo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 gohugoio#3817
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: errorf | ||
linktitle: errorf | ||
description: Evaluates a format string and logs it to ERROR. | ||
date: 2017-09-30 | ||
publishdate: 2017-09-30 | ||
lastmod: 2017-09-30 | ||
categories: [functions] | ||
menu: | ||
docs: | ||
parent: "functions" | ||
keywords: [strings, log, error] | ||
signature: ["errorf FORMAT INPUT"] | ||
workson: [] | ||
hugoversion: | ||
relatedfuncs: [printf] | ||
deprecated: false | ||
aliases: [] | ||
--- | ||
|
||
`errorf` will evaluate a format string, then output the result to the ERROR log. | ||
This will also cause the build to fail. | ||
|
||
``` | ||
{{ errorf "Something went horribly wrong! %s" err }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package fmt | ||
|
||
import ( | ||
jww "github.com/spf13/jwalterweatherman" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestErrorf(t *testing.T) { | ||
errorCount := jww.LogCountForLevel(jww.LevelError) | ||
ns := &Namespace{} | ||
assert.EqualValues(t, ns.Errorf("%s\n", "test error, please ignore."), "test error, please ignore.\n", "") | ||
assert.EqualValues(t, errorCount+1, jww.LogCountForLevel(jww.LevelError), "Error log count not incremented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters