Kevin Wan 3 years ago committed by GitHub
parent cd15c19250
commit f669e1226c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,9 +7,11 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"strings"
"time" "time"
"github.com/tal-tech/go-zero/core/iox" "github.com/tal-tech/go-zero/core/iox"
@ -20,7 +22,10 @@ import (
"github.com/tal-tech/go-zero/rest/internal" "github.com/tal-tech/go-zero/rest/internal"
) )
const slowThreshold = time.Millisecond * 500 const (
limitBodyBytes = 1024
slowThreshold = time.Millisecond * 500
)
type loggedResponseWriter struct { type loggedResponseWriter struct {
w http.ResponseWriter w http.ResponseWriter
@ -156,7 +161,14 @@ func logBrief(r *http.Request, code int, timer *utils.ElapsedTimer, logs *intern
ok := isOkResponse(code) ok := isOkResponse(code)
if !ok { if !ok {
buf.WriteString(fmt.Sprintf("\n%s", dumpRequest(r))) fullReq := dumpRequest(r)
limitReader := io.LimitReader(strings.NewReader(fullReq), limitBodyBytes)
body, err := ioutil.ReadAll(limitReader)
if err != nil {
buf.WriteString(fmt.Sprintf("\n%s", fullReq))
} else {
buf.WriteString(fmt.Sprintf("\n%s", string(body)))
}
} }
body := logs.Flush() body := logs.Flush()

Loading…
Cancel
Save