diff --git a/helpers/general.go b/helpers/general.go index 4bacf3b38..1ea08eb25 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -250,19 +250,32 @@ func NewDistinctFeedbackLogger() *DistinctLogger { return &DistinctLogger{m: make(map[string]bool), logger: &jww.FEEDBACK} } -// DistinctErrorLog cann be used to avoid spamming the logs with errors. -var DistinctErrorLog = NewDistinctErrorLogger() +var ( + // DistinctErrorLog can be used to avoid spamming the logs with errors. + DistinctErrorLog = NewDistinctErrorLogger() + + // 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() } -// Deprecated logs ERROR logs about a deprecation, but only once for a given set of arguments' values. -func Deprecated(object, item, alternative string) { - // deprecatedLogger.Printf("%s's %s is deprecated and will be removed in Hugo %s. Use %s instead.", object, item, NextHugoReleaseVersion(), alternative) - DistinctErrorLog.Printf("%s's %s is deprecated and will be removed in a future release. Use %s instead.", object, item, alternative) +// Deprecated informs about a deprecation, but only once for a given set of arguments' values. +// If the err flag is enabled, it logs as an ERROR (will exit with -1) and the text will +// point at the next Hugo release. +// The idea is two remove an item in two Hugo releases to give users and theme authors +// plenty of time to fix their templates. +func Deprecated(object, item, alternative string, err bool) { + if err { + DistinctErrorLog.Printf("%s's %s is deprecated and will be removed in Hugo %s. Use %s instead.", object, item, NextHugoReleaseVersion(), alternative) + } else { + // Make sure the users see this while avoiding build breakage. This will not lead to an os.Exit(-1) + DistinctFeedbackLog.Printf("WARNING: %s's %s is deprecated and will be removed in a future release. Use %s instead.", object, item, alternative) + } } // SliceToLower goes through the source slice and lowers all values. diff --git a/hugolib/page.go b/hugolib/page.go index ed333deb9..e94b6c942 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -242,18 +242,18 @@ type PageMeta struct { } func (*PageMeta) WordCount() int { - helpers.Deprecated("PageMeta", "WordCount", ".WordCount (on Page)") + helpers.Deprecated("PageMeta", "WordCount", ".WordCount (on Page)", true) return 0 } func (*PageMeta) FuzzyWordCount() int { - helpers.Deprecated("PageMeta", "FuzzyWordCount", ".FuzzyWordCount (on Page)") + helpers.Deprecated("PageMeta", "FuzzyWordCount", ".FuzzyWordCount (on Page)", true) return 0 } func (*PageMeta) ReadingTime() int { - helpers.Deprecated("PageMeta", "ReadingTime", ".ReadingTime (on Page)") + helpers.Deprecated("PageMeta", "ReadingTime", ".ReadingTime (on Page)", true) return 0 } @@ -1565,7 +1565,7 @@ func (p *Page) Hugo() *HugoInfo { func (p *Page) RSSlink() template.HTML { // TODO(bep) we cannot have two of these - helpers.Deprecated(".Page", "RSSlink", "RSSLink") + helpers.Deprecated(".Page", "RSSlink", "RSSLink", false) return p.RSSLink } diff --git a/hugolib/page_test.go b/hugolib/page_test.go index a2e75c7ec..70659f272 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1270,6 +1270,7 @@ func TestIndexPageSimpleMethods(t *testing.T) { } { n := &Page{pageInit: &pageInit{}, Kind: KindHome} + n.RSSLink = "rssLink" if !this.assertFunc(n) { diff --git a/hugolib/site.go b/hugolib/site.go index 8c40393cc..24a7f95cd 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -245,7 +245,7 @@ func (s *SiteInfo) Param(key interface{}) (interface{}, error) { // GetParam gets a site parameter value if found, nil if not. func (s *SiteInfo) GetParam(key string) interface{} { - helpers.Deprecated("SiteInfo", ".GetParam", ".Param") + helpers.Deprecated("SiteInfo", ".GetParam", ".Param", false) v := s.Params[strings.ToLower(key)] if v == nil {