diff --git a/src/framework/middleware/operate_log.go b/src/framework/middleware/operate_log.go index 61346792..32b378f7 100644 --- a/src/framework/middleware/operate_log.go +++ b/src/framework/middleware/operate_log.go @@ -2,7 +2,6 @@ package middleware import ( "encoding/json" - "fmt" "reflect" "strings" "time" @@ -134,8 +133,15 @@ func OperateLog(options Options) gin.HandlerFunc { contentDisposition := c.Writer.Header().Get("Content-Disposition") contentType := c.Writer.Header().Get("Content-Type") content := contentType + contentDisposition - msg := fmt.Sprintf(`{"status":"%d","size":%d,"content-type":"%s"}`, status, c.Writer.Size(), content) - operaLog.OperaMsg = msg + msgByte, err := json.Marshal(map[string]any{ + "status": status, + "size": c.Writer.Size(), + "content-type": content, + }) + if err != nil { + operaLog.OperaMsg = "" + } + operaLog.OperaMsg = string(msgByte) } // 日志记录时间