aboutsummaryrefslogtreecommitdiffhomepage
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-11-01 15:15:34 +0100
committerBjørn Erik Pedersen <[email protected]>2023-11-01 16:40:26 +0100
commit80f793c38d250ca87b6083eb48d7420baaffd02c (patch)
tree445a4a5c681cdb6098886ccf71f643c292414760 /common
parenta9079d7a6305da15d22ce922da36ec12561a71dc (diff)
downloadhugo-80f793c38d250ca87b6083eb48d7420baaffd02c.tar.gz
hugo-80f793c38d250ca87b6083eb48d7420baaffd02c.zip
Avoid double printing INFO deprecation messages
Fixes #11645
Diffstat (limited to 'common')
-rw-r--r--common/loggers/logger.go14
-rw-r--r--common/loggers/logger_test.go18
-rw-r--r--common/loggers/loggerglobal.go6
3 files changed, 18 insertions, 20 deletions
diff --git a/common/loggers/logger.go b/common/loggers/logger.go
index a50502897..bc64ae0e5 100644
--- a/common/loggers/logger.go
+++ b/common/loggers/logger.go
@@ -40,7 +40,7 @@ type Options struct {
Level logg.Level
Stdout io.Writer
Stderr io.Writer
- Distinct bool
+ DistinctLevel logg.Level
StoreErrors bool
HandlerPost func(e *logg.Entry) error
SuppressStatements map[string]bool
@@ -92,8 +92,8 @@ func New(opts Options) Logger {
logHandler = multi.New(handlers...)
var logOnce *logOnceHandler
- if opts.Distinct {
- logOnce = newLogOnceHandler(logg.LevelWarn)
+ if opts.DistinctLevel != 0 {
+ logOnce = newLogOnceHandler(opts.DistinctLevel)
logHandler = newStopHandler(logOnce, logHandler)
}
@@ -137,10 +137,10 @@ func New(opts Options) Logger {
// NewDefault creates a new logger with the default options.
func NewDefault() Logger {
opts := Options{
- Distinct: true,
- Level: logg.LevelWarn,
- Stdout: os.Stdout,
- Stderr: os.Stdout,
+ DistinctLevel: logg.LevelWarn,
+ Level: logg.LevelWarn,
+ Stdout: os.Stdout,
+ Stderr: os.Stdout,
}
return New(opts)
}
diff --git a/common/loggers/logger_test.go b/common/loggers/logger_test.go
index 1b42eff53..6f589aafe 100644
--- a/common/loggers/logger_test.go
+++ b/common/loggers/logger_test.go
@@ -29,10 +29,10 @@ func TestLogDistinct(t *testing.T) {
c := qt.New(t)
opts := loggers.Options{
- Distinct: true,
- StoreErrors: true,
- Stdout: io.Discard,
- Stderr: io.Discard,
+ DistinctLevel: logg.LevelWarn,
+ StoreErrors: true,
+ Stdout: io.Discard,
+ Stderr: io.Discard,
}
l := loggers.New(opts)
@@ -85,7 +85,6 @@ func TestOptionStoreErrors(t *testing.T) {
c.Assert(sb.String(), qt.Contains, "error 1")
c.Assert(sb.String(), qt.Contains, "ERROR")
-
}
func TestLogCount(t *testing.T) {
@@ -124,17 +123,16 @@ func TestSuppressStatements(t *testing.T) {
c.Assert(errorsStr, qt.Not(qt.Contains), "error 1")
c.Assert(errorsStr, qt.Contains, "error 2")
c.Assert(l.LoggCount(logg.LevelError), qt.Equals, 1)
-
}
func TestReset(t *testing.T) {
c := qt.New(t)
opts := loggers.Options{
- StoreErrors: true,
- Distinct: true,
- Stdout: io.Discard,
- Stderr: io.Discard,
+ StoreErrors: true,
+ DistinctLevel: logg.LevelWarn,
+ Stdout: io.Discard,
+ Stderr: io.Discard,
}
l := loggers.New(opts)
diff --git a/common/loggers/loggerglobal.go b/common/loggers/loggerglobal.go
index 8b8e8cfc2..6fd474a69 100644
--- a/common/loggers/loggerglobal.go
+++ b/common/loggers/loggerglobal.go
@@ -31,9 +31,9 @@ func InitGlobalLogger(level logg.Level, panicOnWarnings bool) {
log = New(
Options{
- Level: level,
- Distinct: true,
- HandlerPost: logHookLast,
+ Level: level,
+ DistinctLevel: logg.LevelInfo,
+ HandlerPost: logHookLast,
},
)
}