diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-23 17:26:13 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-23 17:26:13 +0100 |
commit | f1ed89fec41302ef37ad86348063a7a9be4ef587 (patch) | |
tree | 7b9e12aa01140ad0fdcc5358d508d321b977f1bc /helpers/general.go | |
parent | 0a0db9cd259bf14bf38f1c954e39ecaa70f26923 (diff) |
Revise the deprecation strategy
Git users and theme authors two Hugo releases to fix:
1. With a visible warning
2. Then with an ERROR that exits with -1
Fixes #2726
Diffstat (limited to 'helpers/general.go')
-rw-r--r-- | helpers/general.go | 25 |
1 files changed, 19 insertions, 6 deletions
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. |