Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation printing on info level #11643

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions common/loggers/loggerglobal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +31,7 @@ func InitGlobalLogger(panicOnWarnings bool) {

log = New(
Options{
Level: level,
Distinct: true,
HandlerPost: logHookLast,
},
Expand All @@ -49,5 +50,5 @@ func Log() Logger {
var log Logger

func init() {
InitGlobalLogger(false)
InitGlobalLogger(logg.LevelWarn, false)
}
5 changes: 2 additions & 3 deletions config/allconfig/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.).
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
25 changes: 25 additions & 0 deletions testscripts/commands/deprecate.txt
Original file line number Diff line number Diff line change
@@ -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 }}
24 changes: 24 additions & 0 deletions tpl/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 ""
}
Loading