fix ivyz7c9d
fix external_logger
This commit is contained in:
@@ -64,7 +64,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
|
||||
// 记录请求日志
|
||||
if y.logger != nil {
|
||||
y.logger.LogRequest(requestID, code, y.config.URL, y.buildLogData(params, transactionID))
|
||||
y.logger.LogRequest(requestID, transactionID, code, y.config.URL, params)
|
||||
}
|
||||
|
||||
// 获取当前时间戳
|
||||
@@ -86,7 +86,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
// 记录响应日志
|
||||
if y.logger != nil {
|
||||
duration := time.Since(startTime)
|
||||
y.logger.LogResponse(requestID, code, resp.StatusCode, respData, duration)
|
||||
y.logger.LogResponse(requestID, transactionID, code, resp.StatusCode, respData, duration)
|
||||
}
|
||||
|
||||
if retCode == "100000" {
|
||||
@@ -174,7 +174,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
if !retData.Exists() {
|
||||
err = fmt.Errorf("%w: %s", ErrDatasource, "羽山请求retdata为空")
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
|
||||
} else {
|
||||
err = fmt.Errorf("%w: %s", ErrDatasource, "羽山请求未知的状态码")
|
||||
if y.logger != nil {
|
||||
y.logger.LogError(requestID, code, err, y.buildLogData(params, transactionID))
|
||||
y.logger.LogError(requestID, transactionID, code, err, params)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -195,20 +195,6 @@ func (y *YushanService) generateRequestID() string {
|
||||
return fmt.Sprintf("yushan_%x", hash[:8])
|
||||
}
|
||||
|
||||
// buildLogData 构建包含transactionId的日志数据
|
||||
func (y *YushanService) buildLogData(data map[string]interface{}, transactionID string) map[string]interface{} {
|
||||
if transactionID == "" {
|
||||
return data
|
||||
}
|
||||
|
||||
logData := data
|
||||
if logData == nil {
|
||||
logData = make(map[string]interface{})
|
||||
}
|
||||
logData["transaction_id"] = transactionID
|
||||
return logData
|
||||
}
|
||||
|
||||
// GenerateRandomString 生成一个32位的随机字符串订单号
|
||||
func (y *YushanService) GenerateRandomString() (string, error) {
|
||||
// 创建一个16字节的数组
|
||||
|
||||
Reference in New Issue
Block a user