From fb82a5e086ca12947069b0d77de8a4a1c50f4b0c Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 21 Dec 2015 11:55:58 +0100 Subject: [PATCH] Correctly set default logfile location on Windows (fixes #2608) --- cmd/syncthing/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index c12ca302c..05a40cb58 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -222,7 +222,6 @@ func defaultRuntimeOptions() RuntimeOptions { assetDir: os.Getenv("STGUIASSETS"), cpuProfile: os.Getenv("STCPUPROFILE") != "", stRestarting: os.Getenv("STRESTART") != "", - logFile: "-", // Output to stdout logFlags: log.Ltime, } @@ -234,8 +233,12 @@ func defaultRuntimeOptions() RuntimeOptions { options.logFlags = log.Ltime | log.Ldate | log.Lmicroseconds | log.Lshortfile } - if runtime.GOOS == "windows" { - options.logFile = locations[locLogFile] + if runtime.GOOS != "windows" { + // On non-Windows, we explicitly default to "-" which means stdout. On + // Windows, the blank options.logFile will later be replaced with the + // default path, unless the user has manually specified "-" or + // something else. + options.logFile = "-" } return options @@ -299,6 +302,12 @@ func main() { l.Fatalln(err) } + if options.logFile == "" { + // Blank means use the default logfile location. We must set this + // *after* expandLocations above. + options.logFile = locations[locLogFile] + } + if options.showVersion { fmt.Println(LongVersion) return