Open KiddoV opened 1 year ago
There is a temporary plan here:
package main
import (
"log"
"os"
"syscall"
)
const (
kernel32dll = "kernel32.dll"
)
const panicFile = "C:/panic.log"
var globalFile *os.File
func InitPanicFile() error {
log.Println("init panic file in windows mode")
file, err := os.OpenFile(panicFile, os.O_CREATE|os.O_APPEND, 0666)
globalFile = file
if err != nil {
return err
}
kernel32 := syscall.NewLazyDLL(kernel32dll)
setStdHandle := kernel32.NewProc("SetStdHandle")
sh := syscall.STD_ERROR_HANDLE
v, _, err := setStdHandle.Call(uintptr(sh), uintptr(file.Fd()))
if v == 0 {
return err
}
return nil
}
func init() {
err := pc.InitPanicFile()
if err != nil {
println(err)
}
}
func testPanic() {
panic("test panic")
}
func main() {
testPanic()
}
The principle is to redirect standard output
Will try that, thanks!
We have used https://github.com/mitchellh/panicwrap in our projects, works quite well but at the expense of spawning a second process.
@agui2200 How do I make it only log when ERROR occurs? Right now it would log INF
, DEB
logs as well.
@stffabi Will give it a try too, thanks!
@stffabi can you give me an example of how to use https://github.com/mitchellh/panicwrap with Wails? My app is not running after implemented it:
> wails dev
...
Development mode exited
@agui2200 How do I make it only log when ERROR occurs? Right now it would log
INF
,DEB
logs as well.
all panic output can be rewire to C:/panic.log , this code only support win32 platform
Discussed in https://github.com/wailsapp/wails/discussions/2682