Created
August 31, 2014 19:25
-
-
Save calmh/faf19a6c2a7d0fbac806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"syscall" | |
"time" | |
) | |
var ( | |
kernel32 = syscall.MustLoadDLL("kernel32.dll") | |
procSetStdHandle = kernel32.MustFindProc("SetStdHandle") | |
) | |
var panicFile *os.File | |
func init() { | |
var err error | |
panicFile, err = os.OpenFile("panic.txt", os.O_APPEND|os.O_CREATE|os.O_RDWR|os.O_SYNC, 0666) | |
if err != nil { | |
l.Warnln("Panic logging:", err) | |
return | |
} | |
err = SetStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(panicFile.Fd())) | |
if err != nil { | |
l.Warnln("Panic logging:", err) | |
return | |
} | |
fmt.Fprintf(panicFile, "%s %d\n", time.Now(), Version) | |
} | |
func SetStdHandle(stdhandle int32, handle syscall.Handle) error { | |
r0, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0) | |
if r0 == 0 { | |
if e1 != 0 { | |
return error(e1) | |
} | |
return syscall.EINVAL | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment