mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-05 16:46:58 +08:00
@@ -1,4 +1,4 @@
|
||||
// +build linux,!arm64,darwin
|
||||
//go:build (linux && !arm64) || darwin
|
||||
|
||||
package util
|
||||
|
||||
@@ -9,11 +9,12 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666)
|
||||
logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
log.Println("服务启动出错", "打开异常日志文件失败", err)
|
||||
return
|
||||
}
|
||||
os.Stderr.WriteString("\n--------------------------------\n")
|
||||
// 将进程标准出错重定向至文件,进程崩溃时运行时将向该文件记录协程调用栈信息
|
||||
syscall.Dup2(int(logFile.Fd()), int(os.Stderr.Fd()))
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// +build linux,!darwin
|
||||
//go:build linux && !darwin
|
||||
|
||||
package util
|
||||
|
||||
@@ -9,11 +9,12 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666)
|
||||
logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
log.Println("服务启动出错", "打开异常日志文件失败", err)
|
||||
return
|
||||
}
|
||||
os.Stderr.WriteString("\n--------------------------------\n")
|
||||
// 将进程标准出错重定向至文件,进程崩溃时运行时将向该文件记录协程调用栈信息
|
||||
syscall.Dup3(int(logFile.Fd()), int(os.Stderr.Fd()), 0)
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package util
|
||||
|
||||
@@ -27,11 +26,12 @@ func setStdHandle(stdhandle int32, handle syscall.Handle) error {
|
||||
|
||||
// redirectStderr to the file passed in
|
||||
func init() {
|
||||
logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666)
|
||||
logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
|
||||
err = setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(logFile.Fd()))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to redirect stderr to file: %v", err)
|
||||
}
|
||||
// SetStdHandle does not affect prior references to stderr
|
||||
os.Stderr = logFile
|
||||
os.Stderr.WriteString("\n--------------------------------\n")
|
||||
}
|
||||
|
Reference in New Issue
Block a user