优化异常堆栈打印

This commit is contained in:
2024-09-30 16:17:14 +08:00
parent e52d67cfe3
commit 0636dd1b11
3 changed files with 19 additions and 89 deletions

View File

@ -10,9 +10,6 @@ package response
import (
"fmt"
"net/http"
"runtime"
"strconv"
"strings"
"time"
"git.zhangdeman.cn/zhangdeman/exception"
@ -106,33 +103,15 @@ func SendWithStatusOK(ctx *gin.Context, code any, data any) {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:08 2022/6/26
func SendWithException(ctx *gin.Context, e exception.IException, data any) {
func SendWithException(ctx *gin.Context, e exception.IException, data map[string]any) {
if nil == e {
e = exception.NewSuccess(data)
}
if !define.GetHttpHandleConfig().DisableDebugStackOutput {
pcs := make([]uintptr, 128)
n := runtime.Callers(2, pcs)
frames := runtime.CallersFrames(pcs[:n])
var sb strings.Builder
for {
frame, more := frames.Next()
sb.WriteString(frame.Function)
sb.WriteByte('\n')
sb.WriteByte('\t')
sb.WriteString(frame.File)
sb.WriteByte(':')
sb.WriteString(strconv.Itoa(frame.Line))
sb.WriteByte('\n')
if !more {
break
}
if !define.GetHttpHandleConfig().DisableDebugStackOutput && nil != e {
stack := e.GetStack()
if len(stack) > 0 {
fmt.Println(stack)
}
fmt.Println(sb.String())
}
outputData := map[string]any{
"e_data": e.GetData(),