mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
df17684dd4
add file logger to gateway ref issue: #1734 Signed-off-by: Cytown <cytown@gmail.com>
26 lines
532 B
Go
26 lines
532 B
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func initPanicFile(panicFile string) io.WriteCloser {
|
|
file, err := os.OpenFile(panicFile, os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0600)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("error in open panic: %v", err))
|
|
}
|
|
err = windows.SetStdHandle(windows.STD_ERROR_HANDLE, windows.Handle(file.Fd()))
|
|
if err != nil {
|
|
panic(fmt.Sprintf("Failed to redirect stderr to file: %v", err))
|
|
}
|
|
os.Stderr = file
|
|
return file
|
|
}
|