aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-10-31 09:25:28 +0100
committerBjørn Erik Pedersen <[email protected]>2023-10-31 10:42:23 +0100
commitab21433689093a87db68666845d736ad492a056f (patch)
tree70828119c97f18143b41aa8bc904a2d889bf16c6
parent23fcfb7f741a417f53a8ef4997bb68e64631df01 (diff)
downloadhugo-ab21433689093a87db68666845d736ad492a056f.tar.gz
hugo-ab21433689093a87db68666845d736ad492a056f.zip
Fix deprecation printing on info level
Fixes #11638
-rw-r--r--common/loggers/loggerglobal.go5
-rw-r--r--config/allconfig/load.go5
-rw-r--r--hugolib/hugo_sites_build.go3
-rw-r--r--testscripts/commands/deprecate.txt25
-rw-r--r--tpl/debug/debug.go24
5 files changed, 56 insertions, 6 deletions
diff --git a/common/loggers/loggerglobal.go b/common/loggers/loggerglobal.go
index 92b2469ba..8b8e8cfc2 100644
--- a/common/loggers/loggerglobal.go
+++ b/common/loggers/loggerglobal.go
@@ -21,7 +21,7 @@ import (
"github.com/bep/logg"
)
-func InitGlobalLogger(panicOnWarnings bool) {
+func InitGlobalLogger(level logg.Level, panicOnWarnings bool) {
logMu.Lock()
defer logMu.Unlock()
var logHookLast func(e *logg.Entry) error
@@ -31,6 +31,7 @@ func InitGlobalLogger(panicOnWarnings bool) {
log = New(
Options{
+ Level: level,
Distinct: true,
HandlerPost: logHookLast,
},
@@ -49,5 +50,5 @@ func Log() Logger {
var log Logger
func init() {
- InitGlobalLogger(false)
+ InitGlobalLogger(logg.LevelWarn, false)
}
diff --git a/config/allconfig/load.go b/config/allconfig/load.go
index 3af6147da..e7dae1806 100644
--- a/config/allconfig/load.go
+++ b/config/allconfig/load.go
@@ -93,10 +93,10 @@ func LoadConfig(d ConfigSourceDescriptor) (*Configs, error) {
// This is unfortunate, but these are global settings.
tpl.SetSecurityAllowActionJSTmpl(configs.Base.Security.GoTemplates.AllowActionJSTmpl)
- loggers.InitGlobalLogger(configs.Base.PanicOnWarning)
- return configs, nil
+ loggers.InitGlobalLogger(d.Logger.Level(), configs.Base.PanicOnWarning)
+ return configs, nil
}
// ConfigSourceDescriptor describes where to find the config (e.g. config.toml etc.).
@@ -330,7 +330,6 @@ func (l *configLoader) envStringToVal(k, v string) any {
default:
return v
}
-
}
func (l *configLoader) loadConfigMain(d ConfigSourceDescriptor) (config.LoadConfigResult, modules.ModulesConfig, error) {
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index 72b5fe771..a2b87b5e7 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -30,6 +30,7 @@ import (
"github.com/gohugoio/hugo/hugofs"
+ "github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/para"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/resources/postpub"
@@ -172,7 +173,7 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
return err
}
- errorCount := h.Log.LoggCount(logg.LevelError)
+ errorCount := h.Log.LoggCount(logg.LevelError) + loggers.Log().LoggCount(logg.LevelError)
if errorCount > 0 {
return fmt.Errorf("logged %d error(s)", errorCount)
}
diff --git a/testscripts/commands/deprecate.txt b/testscripts/commands/deprecate.txt
new file mode 100644
index 000000000..b15d7ec84
--- /dev/null
+++ b/testscripts/commands/deprecate.txt
@@ -0,0 +1,25 @@
+
+
+hugo -e info --logLevel info
+stdout 'INFO item was deprecated in Hugo'
+
+hugo -e warn --logLevel warn
+stdout 'WARN item was deprecated in Hugo'
+
+! hugo -e error --logLevel warn
+stdout 'ERROR item was deprecated in Hugo'
+
+-- hugo.toml --
+baseURL = "https://example.com/"
+disableKinds = ["taxonomy", "term"]
+-- layouts/index.html --
+Deprecate:
+{{ if eq hugo.Environment "info" }}
+ {{ debug.TestDeprecationInfo "item" "alternative" }}
+{{ end }}
+{{ if eq hugo.Environment "warn" }}
+ {{ debug.TestDeprecationWarn "item" "alternative" }}
+{{ end }}
+{{ if eq hugo.Environment "error" }}
+ {{ debug.TestDeprecationErr "item" "alternative" }}
+{{ end }} \ No newline at end of file
diff --git a/tpl/debug/debug.go b/tpl/debug/debug.go
index dd0593e27..f603dd94d 100644
--- a/tpl/debug/debug.go
+++ b/tpl/debug/debug.go
@@ -24,6 +24,7 @@ import (
"github.com/spf13/cast"
"github.com/yuin/goldmark/util"
+ "github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/deps"
)
@@ -156,3 +157,26 @@ func (t *timer) Stop() string {
// This is used in templates, we need to return something.
return ""
}
+
+// Internal template func, used in tests only.
+func (ns *Namespace) TestDeprecationInfo(item, alternative string) string {
+ v := hugo.CurrentVersion
+ hugo.Deprecate(item, alternative, v.String())
+ return ""
+}
+
+// Internal template func, used in tests only.
+func (ns *Namespace) TestDeprecationWarn(item, alternative string) string {
+ v := hugo.CurrentVersion
+ v.Minor -= 6
+ hugo.Deprecate(item, alternative, v.String())
+ return ""
+}
+
+// Internal template func, used in tests only.
+func (ns *Namespace) TestDeprecationErr(item, alternative string) string {
+ v := hugo.CurrentVersion
+ v.Minor -= 12
+ hugo.Deprecate(item, alternative, v.String())
+ return ""
+}