- don't output binary debug msg
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
@@ -80,7 +82,10 @@ func init() {
|
||||
structs.DefaultTagName = "json"
|
||||
}
|
||||
|
||||
func getClonedData(r *bytes.Buffer) string {
|
||||
func getClonedData(requestURL *url.URL, r *bytes.Buffer) string {
|
||||
if strings.Index(requestURL.String(), "uploadImg") >= 0 {
|
||||
return "binary content"
|
||||
}
|
||||
retVal := string(r.Bytes())
|
||||
if len(retVal) > maxDataSizeDontOutput {
|
||||
return "request data is too large"
|
||||
@@ -101,7 +106,7 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.
|
||||
trackID := utils.GetUUID()
|
||||
baseapi.SugarLogger.Debugf("begin AccessPlatformAPIWithRetry:%s do url:%v", trackID, request.URL)
|
||||
response, err := client.Do(request)
|
||||
baseapi.SugarLogger.Debugf("end AccessPlatformAPIWithRetry:%s do url:%v, request:%s", trackID, request.URL, getClonedData(savedBuf))
|
||||
baseapi.SugarLogger.Debugf("end AccessPlatformAPIWithRetry:%s do url:%v, request:%s", trackID, request.URL, getClonedData(request.URL, savedBuf))
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Debugf("AccessPlatformAPIWithRetry:%s client.Get return err:%v", err)
|
||||
err, ok := err.(net.Error)
|
||||
@@ -109,20 +114,20 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.
|
||||
recoverableErrorRetryCount++
|
||||
continue
|
||||
} else {
|
||||
baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry:%s access api url:%v, request:%v, error:%v", trackID, request.URL, getClonedData(savedBuf), err)
|
||||
baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry:%s access api url:%v, request:%v, error:%v", trackID, request.URL, getClonedData(request.URL, savedBuf), err)
|
||||
return ErrAPIAccessFailed
|
||||
}
|
||||
}
|
||||
usedMilliSecond := time.Now().Sub(beginTime) / time.Millisecond
|
||||
if usedMilliSecond > 5000 {
|
||||
baseapi.SugarLogger.Infof("AccessPlatformAPIWithRetry:%s access api too slow, url:%v, request:%v, usedMilliSecond:%d", trackID, request.URL, getClonedData(savedBuf), usedMilliSecond)
|
||||
baseapi.SugarLogger.Infof("AccessPlatformAPIWithRetry:%s access api too slow, url:%v, request:%v, usedMilliSecond:%d", trackID, request.URL, getClonedData(request.URL, savedBuf), usedMilliSecond)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode != 200 {
|
||||
if bodyData, err := ioutil.ReadAll(response.Body); err == nil {
|
||||
baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry:%s HTTP code is:%d, url:%v, request:%v, response:%s", trackID, response.StatusCode, request.URL, getClonedData(savedBuf), string(bodyData))
|
||||
baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry:%s HTTP code is:%d, url:%v, request:%v, response:%s", trackID, response.StatusCode, request.URL, getClonedData(request.URL, savedBuf), string(bodyData))
|
||||
} else {
|
||||
baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry:%s HTTP code is:%d, url:%v, request:%v", trackID, response.StatusCode, request.URL, getClonedData(savedBuf))
|
||||
baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry:%s HTTP code is:%d, url:%v, request:%v", trackID, response.StatusCode, request.URL, getClonedData(request.URL, savedBuf))
|
||||
}
|
||||
return ErrHTTPCodeIsNot200
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user