Add logging to Google Drive cloud

This commit is contained in:
Julian Raufelder 2021-02-11 21:33:14 +01:00
parent 8dc310bcee
commit a217e58f94
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D
2 changed files with 33 additions and 2 deletions

View File

@ -9,18 +9,49 @@ import com.google.api.services.drive.DriveScopes;
import org.cryptomator.data.BuildConfig;
import org.cryptomator.domain.exception.FatalBackendException;
import org.cryptomator.util.SharedPreferencesHandler;
import java.util.Collections;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import timber.log.Timber;
class GoogleDriveClientFactory {
private final Context context;
private final SharedPreferencesHandler sharedPreferencesHandler;
GoogleDriveClientFactory(Context context) {
GoogleDriveClientFactory(Context context, SharedPreferencesHandler sharedPreferencesHandler) {
this.context = context;
this.sharedPreferencesHandler = sharedPreferencesHandler;
}
Drive getClient(String accountName) throws FatalBackendException {
if(sharedPreferencesHandler.debugMode()) {
Logger.getLogger("com.google.api.client").setLevel(Level.CONFIG);
Logger.getLogger("com.google.api.client").addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
if(record.getMessage().startsWith("-------------- RESPONSE --------------")
|| record.getMessage().startsWith("-------------- REQUEST --------------")
|| record.getMessage().startsWith("{\n \"files\": [\n")) {
Timber.tag("GoogleDriveClient").d(record.getMessage());
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
});
}
try {
FixedGoogleAccountCredential credential = FixedGoogleAccountCredential.usingOAuth2(context, Collections.singleton(DriveScopes.DRIVE));
credential.setAccountName(accountName);

View File

@ -69,7 +69,7 @@ class GoogleDriveImpl {
}
private Drive client() {
return new GoogleDriveClientFactory(context) //
return new GoogleDriveClientFactory(context, sharedPreferencesHandler) //
.getClient(googleDriveCloud.accessToken());
}