log/crash/crash_unix.go

20 lines
355 B
Go
Raw Normal View History

2019-11-05 07:57:09 +00:00
// +build freebsd openbsd netbsd dragonfly linux
package crash
import (
"log"
"os"
"syscall"
)
2019-11-06 02:11:12 +00:00
// NewCrashLog set crash log
func NewCrashLog(file string) {
2019-11-05 07:57:09 +00:00
f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
2019-11-08 09:45:09 +00:00
log.Fatalf("open crash log file error. %v", err)
2019-11-05 07:57:09 +00:00
} else {
2019-11-06 02:11:12 +00:00
_ = syscall.Dup3(int(f.Fd()), 2, 0)
2019-11-05 07:57:09 +00:00
}
}