cmd/syncthing: Use main logger in generate subcommand (fixes #8682) (#8685)

We had some unholy mix of our own logger and the stdlib logger, probably
because for historical reasons we wanted the device ID to stdout and the
rest to stderr? But that's not the case any more, and the mix of formats
is weird. Ideally I think the generate command should be silent and just
print the device ID and nothing else, but that's tricky to accomplish
since we have other methods do logging on their own. Hence this just
harmonizes it so that we at least use the same logger with the same
format and target...
This commit is contained in:
Jakob Borg
2022-11-20 13:48:08 +01:00
committed by GitHub
parent 2a8362d7af
commit 24275b4584
2 changed files with 12 additions and 13 deletions
+2 -1
View File
@@ -251,6 +251,7 @@ func main() {
ctx, err := parser.Parse(args)
parser.FatalIfErrorf(err)
ctx.BindTo(l, (*logger.Logger)(nil)) // main logger available to subcommands
err = ctx.Run()
parser.FatalIfErrorf(err)
}
@@ -345,7 +346,7 @@ func (options serveOptions) Run() error {
}
if options.GenerateDir != "" {
if err := generate.Generate(options.GenerateDir, "", "", options.NoDefaultFolder, options.SkipPortProbing); err != nil {
if err := generate.Generate(l, options.GenerateDir, "", "", options.NoDefaultFolder, options.SkipPortProbing); err != nil {
l.Warnln("Failed to generate config and keys:", err)
os.Exit(svcutil.ExitError.AsInt())
}