1
0
Эх сурвалжийг харах

enhance: recovery print call stack

0xJacky 2 жил өмнө
parent
commit
0bae0e0912

+ 8 - 0
server/internal/logger/logger.go

@@ -74,6 +74,10 @@ func Debug(args ...interface{}) {
 	logger.Debugln(args...)
 }
 
+func DPanic(args ...interface{}) {
+	logger.DPanic(args...)
+}
+
 func Infof(format string, args ...interface{}) {
 	logger.Infof(format, args...)
 }
@@ -86,6 +90,10 @@ func Fatalf(format string, args ...interface{}) {
 	logger.Fatalf(format, args...)
 }
 
+func DPanicf(format string, args ...interface{}) {
+	logger.DPanicf(format, args...)
+}
+
 func Warnf(format string, args ...interface{}) {
 	logger.Warnf(format, args...)
 }

+ 4 - 1
server/router/middleware.go

@@ -12,6 +12,7 @@ import (
 	"io/fs"
 	"net/http"
 	"path"
+	"runtime"
 	"strings"
 )
 
@@ -26,7 +27,9 @@ func recovery() gin.HandlerFunc {
 						errorAction = errorActionMsg
 					}
 				}
-				logger.Error(err)
+				buf := make([]byte, 1024)
+				runtime.Stack(buf, false)
+				logger.Errorf("%s\n%s", err, buf)
 				c.JSON(http.StatusInternalServerError, gin.H{
 					"message": err.(error).Error(),
 					"error":   errorAction,