aboutsummaryrefslogtreecommitdiffhomepage
path: root/commands
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-12-13 09:23:09 +0100
committerGitHub <[email protected]>2024-12-13 09:23:09 +0100
commit9dfa1126177952433f8339a87fb566c2959fc3d6 (patch)
treead9c043d078688e5506f51d44df2474215c8b2b9 /commands
parentec1933f79d0da792d5c853cf7bf99fc9f0961162 (diff)
downloadhugo-9dfa1126177952433f8339a87fb566c2959fc3d6.tar.gz
hugo-9dfa1126177952433f8339a87fb566c2959fc3d6.zip
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
Diffstat (limited to 'commands')
-rw-r--r--commands/commandeer.go21
-rw-r--r--commands/list.go2
2 files changed, 13 insertions, 10 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go
index bb82ec654..3f9f02d23 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -103,7 +103,8 @@ type configKey struct {
type rootCommand struct {
Printf func(format string, v ...interface{})
Println func(a ...interface{})
- Out io.Writer
+ StdOut io.Writer
+ StdErr io.Writer
logger loggers.Logger
@@ -356,7 +357,7 @@ func (r *rootCommand) getOrCreateHugo(cfg config.Provider, ignoreModuleDoesNotEx
}
func (r *rootCommand) newDepsConfig(conf *commonConfig) deps.DepsCfg {
- return deps.DepsCfg{Configs: conf.configs, Fs: conf.fs, LogOut: r.logger.Out(), LogLevel: r.logger.Level(), ChangesFromBuild: r.changesFromBuild}
+ return deps.DepsCfg{Configs: conf.configs, Fs: conf.fs, StdOut: r.logger.StdOut(), StdErr: r.logger.StdErr(), LogLevel: r.logger.Level(), ChangesFromBuild: r.changesFromBuild}
}
func (r *rootCommand) Name() string {
@@ -421,21 +422,23 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
}
func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
- r.Out = os.Stdout
+ r.StdOut = os.Stdout
+ r.StdErr = os.Stderr
if r.quiet {
- r.Out = io.Discard
+ r.StdOut = io.Discard
+ r.StdErr = io.Discard
}
// Used by mkcert (server).
- log.SetOutput(r.Out)
+ log.SetOutput(r.StdOut)
r.Printf = func(format string, v ...interface{}) {
if !r.quiet {
- fmt.Fprintf(r.Out, format, v...)
+ fmt.Fprintf(r.StdOut, format, v...)
}
}
r.Println = func(a ...interface{}) {
if !r.quiet {
- fmt.Fprintln(r.Out, a...)
+ fmt.Fprintln(r.StdOut, a...)
}
}
_, running := runner.Command.(*serverCommand)
@@ -485,8 +488,8 @@ func (r *rootCommand) createLogger(running bool) (loggers.Logger, error) {
optsLogger := loggers.Options{
DistinctLevel: logg.LevelWarn,
Level: level,
- Stdout: r.Out,
- Stderr: r.Out,
+ StdOut: r.StdOut,
+ StdErr: r.StdErr,
StoreErrors: running,
}
diff --git a/commands/list.go b/commands/list.go
index f362e22f1..42f3408ba 100644
--- a/commands/list.go
+++ b/commands/list.go
@@ -57,7 +57,7 @@ func newListCommand() *listCommand {
return err
}
- writer := csv.NewWriter(r.Out)
+ writer := csv.NewWriter(r.StdOut)
defer writer.Flush()
writer.Write([]string{