Implement S3 logging
This commit is contained in:
parent
ee3787e8bb
commit
b6b3cd2d9b
@ -2,7 +2,10 @@ package org.cryptomator.data.cloud.s3;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.amazonaws.Request;
|
||||||
|
import com.amazonaws.Response;
|
||||||
import com.amazonaws.auth.BasicAWSCredentials;
|
import com.amazonaws.auth.BasicAWSCredentials;
|
||||||
|
import com.amazonaws.handlers.RequestHandler2;
|
||||||
import com.amazonaws.regions.Region;
|
import com.amazonaws.regions.Region;
|
||||||
import com.amazonaws.regions.Regions;
|
import com.amazonaws.regions.Regions;
|
||||||
import com.amazonaws.services.s3.AmazonS3;
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
@ -11,6 +14,8 @@ import com.amazonaws.services.s3.AmazonS3Client;
|
|||||||
import org.cryptomator.domain.S3Cloud;
|
import org.cryptomator.domain.S3Cloud;
|
||||||
import org.cryptomator.util.crypto.CredentialCryptor;
|
import org.cryptomator.util.crypto.CredentialCryptor;
|
||||||
|
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
class S3ClientFactory {
|
class S3ClientFactory {
|
||||||
|
|
||||||
private AmazonS3 apiClient;
|
private AmazonS3 apiClient;
|
||||||
@ -38,13 +43,41 @@ class S3ClientFactory {
|
|||||||
client.setEndpoint(cloud.s3Endpoint());
|
client.setEndpoint(cloud.s3Endpoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.addRequestHandler(new LoggingAwareRequestHandler());
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String decrypt(String password, Context context) {
|
private String decrypt(String password, Context context) {
|
||||||
return CredentialCryptor //
|
return CredentialCryptor //
|
||||||
.getInstance(context) //
|
.getInstance(context) //
|
||||||
.decrypt(password);
|
.decrypt(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class LoggingAwareRequestHandler extends RequestHandler2 {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeRequest(Request<?> request) {
|
||||||
|
Timber.tag("S3Client").d("Sending request (%s) %s", request.getAWSRequestMetrics().getTimingInfo().getStartTimeNano(), request.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterResponse(Request<?> request, Response<?> response) {
|
||||||
|
Timber.tag("S3Client").d( //
|
||||||
|
"Response received (%s) with status %s (%s)", //
|
||||||
|
request.getAWSRequestMetrics().getTimingInfo().getStartTimeNano(), //
|
||||||
|
response.getHttpResponse().getStatusText(), //
|
||||||
|
response.getHttpResponse().getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterError(Request<?> request, Response<?> response, Exception e) {
|
||||||
|
Timber.tag("S3Client").e( //
|
||||||
|
e,
|
||||||
|
"Error occurred (%s) with status %s (%s)", //
|
||||||
|
request.getAWSRequestMetrics().getTimingInfo().getStartTimeNano(), //
|
||||||
|
response.getHttpResponse().getStatusText(), //
|
||||||
|
response.getHttpResponse().getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user