Skip to content

Commit 812ea0b

Browse files
committed
config: Use the non-global logger for deprecations when possible
To prevent warnings leaking into parallel tests.
1 parent 07cbe57 commit 812ea0b

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

common/hugo/hugo.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -411,25 +411,36 @@ func IsDartSassGeV2() bool {
411411
// 2. Their theme to work for at least the last few Hugo versions.
412412
func Deprecate(item, alternative string, version string) {
413413
level := deprecationLogLevelFromVersion(version)
414-
DeprecateLevel(item, alternative, version, level)
414+
deprecateLevel(item, alternative, version, level)
415+
}
416+
417+
// See Deprecate for details.
418+
func DeprecateWithLogger(item, alternative string, version string, log logg.Logger) {
419+
level := deprecationLogLevelFromVersion(version)
420+
deprecateLevelWithLogger(item, alternative, version, level, log)
415421
}
416422

417423
// DeprecateLevelMin informs about a deprecation starting at the given version, but with a minimum log level.
418424
func DeprecateLevelMin(item, alternative string, version string, minLevel logg.Level) {
419425
level := max(deprecationLogLevelFromVersion(version), minLevel)
420-
DeprecateLevel(item, alternative, version, level)
426+
deprecateLevel(item, alternative, version, level)
427+
}
428+
429+
// deprecateLevel informs about a deprecation logging at the given level.
430+
func deprecateLevel(item, alternative, version string, level logg.Level) {
431+
deprecateLevelWithLogger(item, alternative, version, level, loggers.Log().Logger())
421432
}
422433

423434
// DeprecateLevel informs about a deprecation logging at the given level.
424-
func DeprecateLevel(item, alternative, version string, level logg.Level) {
435+
func deprecateLevelWithLogger(item, alternative, version string, level logg.Level, log logg.Logger) {
425436
var msg string
426437
if level == logg.LevelError {
427438
msg = fmt.Sprintf("%s was deprecated in Hugo %s and subsequently removed. %s", item, version, alternative)
428439
} else {
429440
msg = fmt.Sprintf("%s was deprecated in Hugo %s and will be removed in a future release. %s", item, version, alternative)
430441
}
431442

432-
loggers.Log().Logger().WithLevel(level).WithField(loggers.FieldNameCmd, "deprecated").Logf("%s", msg)
443+
log.WithLevel(level).WithField(loggers.FieldNameCmd, "deprecated").Logf("%s", msg)
433444
}
434445

435446
// We usually do about one minor version a month.

config/allconfig/allconfig.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -396,44 +396,44 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
396396

397397
// Legacy paginate values.
398398
if c.Paginate != 0 {
399-
hugo.Deprecate("site config key paginate", "Use pagination.pagerSize instead.", "v0.128.0")
399+
hugo.DeprecateWithLogger("site config key paginate", "Use pagination.pagerSize instead.", "v0.128.0", logger.Logger())
400400
c.Pagination.PagerSize = c.Paginate
401401
}
402402

403403
if c.PaginatePath != "" {
404-
hugo.Deprecate("site config key paginatePath", "Use pagination.path instead.", "v0.128.0")
404+
hugo.DeprecateWithLogger("site config key paginatePath", "Use pagination.path instead.", "v0.128.0", logger.Logger())
405405
c.Pagination.Path = c.PaginatePath
406406
}
407407

408408
// Legacy privacy values.
409409
if c.Privacy.Twitter.Disable {
410-
hugo.Deprecate("site config key privacy.twitter.disable", "Use privacy.x.disable instead.", "v0.141.0")
410+
hugo.DeprecateWithLogger("site config key privacy.twitter.disable", "Use privacy.x.disable instead.", "v0.141.0", logger.Logger())
411411
c.Privacy.X.Disable = c.Privacy.Twitter.Disable
412412
}
413413

414414
if c.Privacy.Twitter.EnableDNT {
415-
hugo.Deprecate("site config key privacy.twitter.enableDNT", "Use privacy.x.enableDNT instead.", "v0.141.0")
415+
hugo.DeprecateWithLogger("site config key privacy.twitter.enableDNT", "Use privacy.x.enableDNT instead.", "v0.141.0", logger.Logger())
416416
c.Privacy.X.EnableDNT = c.Privacy.Twitter.EnableDNT
417417
}
418418

419419
if c.Privacy.Twitter.Simple {
420-
hugo.Deprecate("site config key privacy.twitter.simple", "Use privacy.x.simple instead.", "v0.141.0")
420+
hugo.DeprecateWithLogger("site config key privacy.twitter.simple", "Use privacy.x.simple instead.", "v0.141.0", logger.Logger())
421421
c.Privacy.X.Simple = c.Privacy.Twitter.Simple
422422
}
423423

424424
// Legacy services values.
425425
if c.Services.Twitter.DisableInlineCSS {
426-
hugo.Deprecate("site config key services.twitter.disableInlineCSS", "Use services.x.disableInlineCSS instead.", "v0.141.0")
426+
hugo.DeprecateWithLogger("site config key services.twitter.disableInlineCSS", "Use services.x.disableInlineCSS instead.", "v0.141.0", logger.Logger())
427427
c.Services.X.DisableInlineCSS = c.Services.Twitter.DisableInlineCSS
428428
}
429429

430430
// Legacy permalink tokens
431431
vs := fmt.Sprintf("%v", c.Permalinks)
432432
if strings.Contains(vs, ":filename") {
433-
hugo.Deprecate("the \":filename\" permalink token", "Use \":contentbasename\" instead.", "0.144.0")
433+
hugo.DeprecateWithLogger("the \":filename\" permalink token", "Use \":contentbasename\" instead.", "0.144.0", logger.Logger())
434434
}
435435
if strings.Contains(vs, ":slugorfilename") {
436-
hugo.Deprecate("the \":slugorfilename\" permalink token", "Use \":slugorcontentbasename\" instead.", "0.144.0")
436+
hugo.DeprecateWithLogger("the \":slugorfilename\" permalink token", "Use \":slugorcontentbasename\" instead.", "0.144.0", logger.Logger())
437437
}
438438

439439
c.C = &ConfigCompiled{

0 commit comments

Comments
 (0)