|
@@ -58,6 +58,7 @@ func GinLogger() gin.HandlerFunc {
|
|
zap.String("time", cost.String()),
|
|
zap.String("time", cost.String()),
|
|
zap.String("Request body", string(requestBody)),
|
|
zap.String("Request body", string(requestBody)),
|
|
zap.String("Response body", w.body.String()),
|
|
zap.String("Response body", w.body.String()),
|
|
|
|
+ zap.String("x-request-id", c.GetHeader("X-Request-ID")),
|
|
}
|
|
}
|
|
if len(c.Errors) > 0 {
|
|
if len(c.Errors) > 0 {
|
|
logFields = append(logFields, zap.Any("stack", string(debug.Stack())))
|
|
logFields = append(logFields, zap.Any("stack", string(debug.Stack())))
|
|
@@ -74,41 +75,6 @@ func GinRecovery(stack bool) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
defer func() {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
if err := recover(); err != nil {
|
|
- /*// Check for a broken connection, as it is not really a
|
|
|
|
- // condition that warrants a panic stack trace.
|
|
|
|
- var brokenPipe bool
|
|
|
|
- if ne, ok := err.(*net.OpError); ok {
|
|
|
|
- if se, ok := ne.Err.(*os.SyscallError); ok {
|
|
|
|
- if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
|
|
|
|
- brokenPipe = true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- httpRequest, _ := httputil.DumpRequest(c.Request, false)
|
|
|
|
- if brokenPipe {
|
|
|
|
- zaplog.Error(c.Request.URL.Path,
|
|
|
|
- zap.Any("error", err),
|
|
|
|
- zap.String("request", string(httpRequest)),
|
|
|
|
- )
|
|
|
|
- // If the connection is dead, we can't write a status to it.
|
|
|
|
- c.Error(err.(error)) // nolint: errcheck
|
|
|
|
- c.Abort()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if stack {
|
|
|
|
- zaplog.Error("[Recovery from panic]",
|
|
|
|
- zap.Any("error", err),
|
|
|
|
- zap.String("request", string(httpRequest)),
|
|
|
|
- zap.String("stack", string(debug.Stack())),
|
|
|
|
- )
|
|
|
|
- } else {
|
|
|
|
- zaplog.Error("[Recovery from panic]",
|
|
|
|
- zap.Any("error", err),
|
|
|
|
- zap.String("request", string(httpRequest)),
|
|
|
|
- )
|
|
|
|
- }*/
|
|
|
|
defer func() {
|
|
defer func() {
|
|
if err = recover(); err != nil {
|
|
if err = recover(); err != nil {
|
|
body, _ := ioutil.ReadAll(c.Request.Body)
|
|
body, _ := ioutil.ReadAll(c.Request.Body)
|