Skip to content

Commit d4ee341

Browse files
authored
Merge pull request #183 from tencentyun/dev/presigned_url_encode
log coding
2 parents 6e94732 + 7f6444c commit d4ee341

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
package com.qcloud.cos.exception;
22

33
public class ExceptionLogDetail {
4-
public ExceptionLogDetail(Throwable t, String exception_level, long time_stamp, int execute_index) {
4+
public ExceptionLogDetail(Throwable t, String msg) {
55
this.t = t;
6-
this.exception_level = exception_level;
7-
this.time_stamp = time_stamp;
8-
this.execute_index = execute_index;
9-
}
10-
11-
public long getTimeStamp() {
12-
return time_stamp;
13-
}
14-
15-
public String getExceptionLevel() {
16-
return exception_level;
6+
this.err_msg = msg;
177
}
188

199
public Throwable getException() {
2010
return t;
2111
}
2212

23-
public int getExecuteIndex() {
24-
return execute_index;
13+
public String getErrMsg() {
14+
return err_msg;
2515
}
2616

27-
private long time_stamp;
28-
2917
private Throwable t;
3018

31-
private String exception_level;
32-
33-
private int execute_index;
19+
private String err_msg;
3420
}

src/main/java/com/qcloud/cos/http/DefaultCosHttpClient.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,23 @@ public <X, Y extends CosServiceRequest> X exeute(CosHttpRequest<Y> request,
512512
break;
513513
} catch (CosServiceException cse) {
514514
closeHttpResponseStream(httpResponse);
515-
request.addLogDetails(new ExceptionLogDetail(cse, "service", System.currentTimeMillis(), retryIndex));
515+
String errorMsg = String.format("failed to execute http request due to service exception, request timeStamp %d,"
516+
+ " httpRequest: %s, retryIdx:%d, maxErrorRetry:%d", System.currentTimeMillis(), request,
517+
retryIndex, maxErrorRetry);
518+
request.addLogDetails(new ExceptionLogDetail(cse, errorMsg));
516519
if (!shouldRetry(request, httpResponse, cse, retryIndex, retryPolicy)) {
517-
if (cse.getStatusCode() >= 500) {
520+
if (cse.getStatusCode() >= 400) {
518521
handleLog(request);
519522
}
520523
throw cse;
521524
}
522525
changeEndpointForRetry(request, httpResponse, retryIndex);
523526
} catch (CosClientException cce) {
524527
closeHttpResponseStream(httpResponse);
525-
request.addLogDetails(new ExceptionLogDetail(cce, "client", System.currentTimeMillis(), retryIndex));
528+
String errorMsg = String.format("failed to execute http request due to client exception, request timeStamp %d,"
529+
+ " httpRequest: %s, retryIdx:%d, maxErrorRetry:%d", System.currentTimeMillis(), request,
530+
retryIndex, maxErrorRetry);
531+
request.addLogDetails(new ExceptionLogDetail(cce, errorMsg));
526532
if (!shouldRetry(request, httpResponse, cce, retryIndex, retryPolicy)) {
527533
handleLog(request);
528534
throw cce;
@@ -631,10 +637,7 @@ private HttpResponse executeRequest(HttpContext context, HttpRequestBase httpReq
631637

632638
private <Y extends CosServiceRequest> void handleLog(CosHttpRequest<Y> request) {
633639
for (ExceptionLogDetail logDetail : request.getExceptionsLogDetails()) {
634-
String errorMsg = String.format("failed to execute http request due to %s exception, request timeStamp %d,"
635-
+ " httpRequest: %s, retryIdx:%d, maxErrorRetry:%d", logDetail.getExceptionLevel(), logDetail.getTimeStamp(), request,
636-
logDetail.getExecuteIndex(), maxErrorRetry);
637-
log.error(errorMsg, logDetail.getException());
640+
log.error(logDetail.getErrMsg(), logDetail.getException());
638641
}
639642
}
640643

0 commit comments

Comments
 (0)