Add ability to set log file in command line options

This commit is contained in:
Gary Talent 2017-01-27 19:48:03 -06:00
parent 10a959e9f3
commit 42e65ebf52

View File

@ -10,6 +10,7 @@ package main
import (
"flag"
"log"
"os"
)
const (
@ -19,6 +20,7 @@ const (
type cmdOptions struct {
config string
logFile string
cmd string
}
@ -26,6 +28,7 @@ func parseCmdOptions() cmdOptions {
var o cmdOptions
flag.StringVar(&o.cmd, "cmd", CMD_SERVE, "Mode to run command in ("+CMD_SERVE+","+CMD_SPINDOWNALL+")")
flag.StringVar(&o.config, "config", "dospin.json", "Path to the dospin config file")
flag.StringVar(&o.logFile, "logFile", "stdout", "Path to the dospin log file")
flag.Parse()
return o
}
@ -45,6 +48,15 @@ func spindownAll(opts cmdOptions) {
}
func runServer(opts cmdOptions) {
if opts.logFile != "stdout" {
logFile, err := os.OpenFile(opts.logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
if err == nil {
log.SetOutput(logFile)
} else {
log.Print("Could not open log file: ", err)
}
}
log.Println("Loading config:", opts.config)
settings, err := loadSettings(opts.config)
if err != nil {