Skip to content

Commit

Permalink
hugolib, helpers: Reduce log level to WARN on .Render for non-regular…
Browse files Browse the repository at this point in the history
… pages

We will eventually support all types in the Render method.
  • Loading branch information
bep committed Mar 29, 2017
1 parent 5989c4d commit 87b3cd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion helpers/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ func NewDistinctErrorLogger() *DistinctLogger {
return &DistinctLogger{m: make(map[string]bool), logger: jww.ERROR}
}

// NewDistinctWarnLogger creates a new DistinctLogger that logs WARNs
func NewDistinctWarnLogger() *DistinctLogger {
return &DistinctLogger{m: make(map[string]bool), logger: jww.WARN}
}

// NewDistinctFeedbackLogger creates a new DistinctLogger that can be used
// to give feedback to the user while not spamming with duplicates.
func NewDistinctFeedbackLogger() *DistinctLogger {
Expand All @@ -260,13 +265,16 @@ var (
// DistinctErrorLog can be used to avoid spamming the logs with errors.
DistinctErrorLog = NewDistinctErrorLogger()

// DistinctWarnLog can be used to avoid spamming the logs with warnings.
DistinctWarnLog = NewDistinctWarnLogger()

// DistinctFeedbackLog can be used to avoid spamming the logs with info messages.
DistinctFeedbackLog = NewDistinctFeedbackLogger()
)

// InitLoggers sets up the global distinct loggers.
func InitLoggers() {
DistinctErrorLog = NewDistinctErrorLogger()
jww.ResetLogCounters()
}

// Deprecated informs about a deprecation, but only once for a given set of arguments' values.
Expand Down
6 changes: 3 additions & 3 deletions hugolib/page_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p *PageOutput) layouts(layouts ...string) ([]string, error) {

func (p *PageOutput) Render(layout ...string) template.HTML {
if !p.checkRender() {
return template.HTML("")
return ""
}

l, err := p.layouts(layout...)
Expand All @@ -117,7 +117,7 @@ func (p *PageOutput) Render(layout ...string) template.HTML {

func (p *Page) Render(layout ...string) template.HTML {
if !p.checkRender() {
return template.HTML("")
return ""
}

p.pageOutputInit.Do(func() {
Expand All @@ -142,7 +142,7 @@ func (p *Page) Render(layout ...string) template.HTML {
// for list pages.
func (p *Page) checkRender() bool {
if p.Kind != KindPage {
helpers.DistinctErrorLog.Printf(".Render only available for regular pages, not for of kind %q. You probably meant .Site.RegularPages and not.Site.Pages.", p.Kind)
helpers.DistinctWarnLog.Printf(".Render only available for regular pages, not for of kind %q. You probably meant .Site.RegularPages and not.Site.Pages.", p.Kind)
return false
}
return true
Expand Down

0 comments on commit 87b3cd4

Please sign in to comment.