This commit is contained in:
runzexia
2019-05-13 10:43:00 +08:00
committed by zryfish
parent 1270e36c2d
commit 996d6fe4c5
3 changed files with 28 additions and 36 deletions

24
pkg/server/server.go Normal file
View File

@@ -0,0 +1,24 @@
package server
import (
"bytes"
"fmt"
"github.com/golang/glog"
"net/http"
"runtime"
)
func LogStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter) {
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintf("recover from panic situation: - %v\r\n", panicReason))
for i := 2; ; i += 1 {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
buffer.WriteString(fmt.Sprintf(" %s:%d\r\n", file, line))
}
glog.Error(buffer.String())
httpWriter.WriteHeader(http.StatusInternalServerError)
httpWriter.Write([]byte("recover from panic situation"))
}