Write all logging (INFO, WARN, ERROR) to stderr

The old setup tried to log >= warning to stderr, the rest to stdout.

However, that logic was flawed, so warnings ended up in stdout, which makes `hugo list all` etc. hard to reason about from scripts.

This commit fixes this by making all logging (info, warn, error) log to stderr and let stdout be reserved for program output.

Fixes #13074
This commit is contained in:
Bjørn Erik Pedersen
2024-12-13 09:23:09 +01:00
committed by GitHub
parent ec1933f79d
commit 9dfa112617
15 changed files with 85 additions and 59 deletions

View File

@@ -660,8 +660,8 @@ func (s *IntegrationTestBuilder) initBuilder() error {
logger := loggers.New(
loggers.Options{
Stdout: w,
Stderr: w,
StdOut: w,
StdErr: w,
Level: s.Cfg.LogLevel,
DistinctLevel: logg.LevelWarn,
},
@@ -685,7 +685,7 @@ func (s *IntegrationTestBuilder) initBuilder() error {
s.Assert(err, qt.IsNil)
depsCfg := deps.DepsCfg{Configs: res, Fs: fs, LogLevel: logger.Level(), LogOut: logger.Out()}
depsCfg := deps.DepsCfg{Configs: res, Fs: fs, LogLevel: logger.Level(), StdErr: logger.StdErr()}
sites, err := NewHugoSites(depsCfg)
if err != nil {
initErr = err

View File

@@ -145,8 +145,11 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
if cfg.Configs.Base.PanicOnWarning {
logHookLast = loggers.PanicOnWarningHook
}
if cfg.LogOut == nil {
cfg.LogOut = os.Stdout
if cfg.StdOut == nil {
cfg.StdOut = os.Stdout
}
if cfg.StdErr == nil {
cfg.StdErr = os.Stderr
}
if cfg.LogLevel == 0 {
cfg.LogLevel = logg.LevelWarn
@@ -156,8 +159,8 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
Level: cfg.LogLevel,
DistinctLevel: logg.LevelWarn, // This will drop duplicate log warning and errors.
HandlerPost: logHookLast,
Stdout: cfg.LogOut,
Stderr: cfg.LogOut,
StdOut: cfg.StdOut,
StdErr: cfg.StdErr,
StoreErrors: conf.Watching(),
SuppressStatements: conf.IgnoredLogs(),
}