Add --log-file flag to log everything (including panics) to file

This commit is contained in:
Nick Craig-Wood
2015-02-27 16:51:17 +00:00
parent e89ea3360e
commit 24a6ff54c2
6 changed files with 94 additions and 5 deletions

19
redirect_stderr_unix.go Normal file
View File

@ -0,0 +1,19 @@
// Log the panic under unix to the log file
//+build unix
package main
import (
"log"
"os"
"syscall"
)
// redirectStderr to the file passed in
func redirectStderr(f *os.File) {
err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err)
}
}