Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Server can now output logs to a file
  • Loading branch information
sionide21 committed Nov 21, 2010
1 parent 4276ac5 commit 744c1a9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server.go
Expand Up @@ -20,6 +20,7 @@ var port = flag.Uint("p", 1234, "Specifies the port to listen on.")
var configFile = flag.String("c", "config.json", "Specify a config file.")
var dataFile = flag.String("d", "", "Specify a data file.")
var displayHelp = flag.Bool("help", false, "Displays this help message.")
var logFile = flag.String("log", "stderr", "Print errors to logfile.")

type ServerConfig struct {
Sekritz map[string]string
Expand Down Expand Up @@ -83,8 +84,17 @@ func verify(a *Auth, d Byter) (bool, os.Error) {


func main() {
log.SetOutput(os.Stderr)
flag.Parse()
if *logFile == "stderr" {
log.SetOutput(os.Stderr)
} else {
logger, err := os.Open(*logFile, os.O_WRONLY|os.O_CREATE, 0640)
if err != nil {
log.SetOutput(os.Stderr)
log.Exit(err)
}
log.SetOutput(logger)
}

if *displayHelp {
flag.PrintDefaults()
Expand Down

0 comments on commit 744c1a9

Please sign in to comment.