调整gin错误日志输出
This commit is contained in:
parent
ddc38eb2cb
commit
570448606e
9
init.go
9
init.go
@ -5,11 +5,9 @@ import (
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"joylink.club/bj-rtsts-server/db/dbquery"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
@ -54,6 +52,7 @@ func InitServer() *gin.Engine {
|
||||
be = sys_error.New("未知错误", fmt.Errorf("%v", e))
|
||||
}
|
||||
}
|
||||
c.Error(be)
|
||||
c.JSON(http.StatusInternalServerError, &dto.ErrorDto{
|
||||
Tip: be.UserMsg,
|
||||
Message: be.Error(),
|
||||
@ -79,11 +78,9 @@ func CustomRecoveryWithSlog(logger *slog.Logger, stack bool, recovery gin.Recove
|
||||
}
|
||||
}
|
||||
|
||||
httpRequest, _ := httputil.DumpRequest(c.Request, false)
|
||||
if brokenPipe {
|
||||
logger.Error(c.Request.URL.Path,
|
||||
"error", err,
|
||||
"request", string(httpRequest),
|
||||
)
|
||||
// If the connection is dead, we can't write a status to it.
|
||||
c.Error(err.(error)) // nolint: errcheck
|
||||
@ -93,17 +90,13 @@ func CustomRecoveryWithSlog(logger *slog.Logger, stack bool, recovery gin.Recove
|
||||
|
||||
if stack {
|
||||
logger.Error("请求处理Panic异常",
|
||||
"time", time.Now(),
|
||||
"error", err,
|
||||
"request", string(httpRequest),
|
||||
"stack", string(debug.Stack()),
|
||||
)
|
||||
debug.PrintStack()
|
||||
} else {
|
||||
logger.Error("请求处理Panic异常",
|
||||
"time", time.Now(),
|
||||
"error", err,
|
||||
"request", string(httpRequest),
|
||||
)
|
||||
}
|
||||
recovery(c, err)
|
||||
|
Loading…
Reference in New Issue
Block a user