Move logFlags into RuntimeOptions

This commit is contained in:
Anderson Mesquita 2015-12-18 11:34:39 -05:00
parent d10e81fb3d
commit 490962ccdb

View File

@ -110,15 +110,10 @@ func init() {
date := BuildDate.UTC().Format("2006-01-02 15:04:05 MST") date := BuildDate.UTC().Format("2006-01-02 15:04:05 MST")
LongVersion = fmt.Sprintf(`syncthing %s "%s" (%s %s-%s) %s@%s %s`, Version, Codename, runtime.Version(), runtime.GOOS, runtime.GOARCH, BuildUser, BuildHost, date) LongVersion = fmt.Sprintf(`syncthing %s "%s" (%s %s-%s) %s@%s %s`, Version, Codename, runtime.Version(), runtime.GOOS, runtime.GOARCH, BuildUser, BuildHost, date)
if os.Getenv("STTRACE") != "" {
logFlags = log.Ltime | log.Ldate | log.Lmicroseconds | log.Lshortfile
}
} }
var ( var (
myID protocol.DeviceID myID protocol.DeviceID
logFlags = log.Ltime
stop = make(chan int) stop = make(chan int)
cert tls.Certificate cert tls.Certificate
lans []*net.IPNet lans []*net.IPNet
@ -217,6 +212,7 @@ type RuntimeOptions struct {
guiAssets string guiAssets string
cpuProfile bool cpuProfile bool
stRestarting bool stRestarting bool
logFlags int
} }
func defaultRuntimeOptions() RuntimeOptions { func defaultRuntimeOptions() RuntimeOptions {
@ -227,12 +223,17 @@ func defaultRuntimeOptions() RuntimeOptions {
cpuProfile: os.Getenv("STCPUPROFILE") != "", cpuProfile: os.Getenv("STCPUPROFILE") != "",
stRestarting: os.Getenv("STRESTART") != "", stRestarting: os.Getenv("STRESTART") != "",
logFile: "-", // Output to stdout logFile: "-", // Output to stdout
logFlags: log.Ltime,
} }
if options.guiAssets != "" { if options.guiAssets != "" {
options.guiAssets = locations[locGUIAssets] options.guiAssets = locations[locGUIAssets]
} }
if os.Getenv("STTRACE") != "" {
options.logFlags = log.Ltime | log.Ldate | log.Lmicroseconds | log.Lshortfile
}
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
options.logFile = locations[locLogFile] options.logFile = locations[locLogFile]
} }
@ -247,7 +248,7 @@ func parseCommandLineOptions() RuntimeOptions {
flag.StringVar(&options.guiAddress, "gui-address", options.guiAddress, "Override GUI address (e.g. \"http://192.0.2.42:8443\")") flag.StringVar(&options.guiAddress, "gui-address", options.guiAddress, "Override GUI address (e.g. \"http://192.0.2.42:8443\")")
flag.StringVar(&options.guiAPIKey, "gui-apikey", options.guiAPIKey, "Override GUI API key") flag.StringVar(&options.guiAPIKey, "gui-apikey", options.guiAPIKey, "Override GUI API key")
flag.StringVar(&options.confDir, "home", "", "Set configuration directory") flag.StringVar(&options.confDir, "home", "", "Set configuration directory")
flag.IntVar(&logFlags, "logflags", logFlags, "Select information in log line prefix (see below)") flag.IntVar(&options.logFlags, "logflags", options.logFlags, "Select information in log line prefix (see below)")
flag.BoolVar(&options.noBrowser, "no-browser", false, "Do not start browser") flag.BoolVar(&options.noBrowser, "no-browser", false, "Do not start browser")
flag.BoolVar(&options.browserOnly, "browser-only", false, "Open GUI in browser") flag.BoolVar(&options.browserOnly, "browser-only", false, "Open GUI in browser")
flag.BoolVar(&options.noRestart, "no-restart", options.noRestart, "Do not restart; just exit") flag.BoolVar(&options.noRestart, "no-restart", options.noRestart, "Do not restart; just exit")
@ -274,6 +275,7 @@ func parseCommandLineOptions() RuntimeOptions {
func main() { func main() {
options := parseCommandLineOptions() options := parseCommandLineOptions()
l.SetFlags(options.logFlags)
if options.guiAddress != "" { if options.guiAddress != "" {
// The config picks this up from the environment. // The config picks this up from the environment.
@ -307,8 +309,6 @@ func main() {
return return
} }
l.SetFlags(logFlags)
if options.generateDir != "" { if options.generateDir != "" {
generate(options.generateDir) generate(options.generateDir)
return return