Skip to content

Commit

Permalink
Avoid double printing INFO deprecation messages
Browse files Browse the repository at this point in the history
Fixes #11645
  • Loading branch information
bep committed Nov 1, 2023
1 parent a9079d7 commit 80f793c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
10 changes: 5 additions & 5 deletions commands/commandeer.go
Expand Up @@ -441,11 +441,11 @@ func (r *rootCommand) createLogger(running bool) (loggers.Logger, error) {
}

optsLogger := loggers.Options{
Distinct: true,
Level: level,
Stdout: r.Out,
Stderr: r.Out,
StoreErrors: running,
DistinctLevel: logg.LevelWarn,
Level: level,
Stdout: r.Out,
Stderr: r.Out,
StoreErrors: running,
}

return loggers.New(optsLogger), nil
Expand Down
14 changes: 7 additions & 7 deletions common/loggers/logger.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
18 changes: 8 additions & 10 deletions common/loggers/logger_test.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions common/loggers/loggerglobal.go
Expand Up @@ -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,
},
)
}
Expand Down
8 changes: 4 additions & 4 deletions hugolib/integrationtest_builder.go
Expand Up @@ -394,10 +394,10 @@ func (s *IntegrationTestBuilder) initBuilder() error {

logger := loggers.New(
loggers.Options{
Stdout: w,
Stderr: w,
Level: s.Cfg.LogLevel,
Distinct: true,
Stdout: w,
Stderr: w,
Level: s.Cfg.LogLevel,
DistinctLevel: logg.LevelWarn,
},
)

Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_new.go
Expand Up @@ -117,7 +117,7 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {

logOpts := loggers.Options{
Level: cfg.LogLevel,
Distinct: true, // This will drop duplicate log warning and errors.
DistinctLevel: logg.LevelWarn, // This will drop duplicate log warning and errors.
HandlerPost: logHookLast,
Stdout: cfg.LogOut,
Stderr: cfg.LogOut,
Expand Down

0 comments on commit 80f793c

Please sign in to comment.