From 9aead170907e059e06a9ed6775a651bb984ca46d Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 18 Apr 2024 12:55:43 +0600 Subject: [PATCH] chore: replace exception.printStackTrace with timber Some exceptions are logging with printStackTrace. So some exceptions are not reported to sentry (if enabled) & some low-level unwanted logs are printed always. Move these logs to Timber.e & Timber.d respectively, so the logcat is clean by default & sentry can report more useful data. --- .../foundation/e/drive/account/AccountUserInfoWorker.java | 2 +- .../java/foundation/e/drive/account/GetAliasOperation.java | 7 +++---- .../main/java/foundation/e/drive/utils/CommonUtils.java | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java b/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java index c1361c95..a295ee45 100644 --- a/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java +++ b/app/src/main/java/foundation/e/drive/account/AccountUserInfoWorker.java @@ -235,7 +235,7 @@ public class AccountUserInfoWorker extends Worker { } } accountManager.setUserData(account, ACCOUNT_DATA_ALIAS_KEY, aliases); - Timber.d("fetchAliases(): success"); + Timber.d("fetchAliases(): success: %s", ocsResult.isSuccess()); DavClientProvider.getInstance().saveAccounts(mContext); diff --git a/app/src/main/java/foundation/e/drive/account/GetAliasOperation.java b/app/src/main/java/foundation/e/drive/account/GetAliasOperation.java index 2f7d26d5..5896f3ed 100644 --- a/app/src/main/java/foundation/e/drive/account/GetAliasOperation.java +++ b/app/src/main/java/foundation/e/drive/account/GetAliasOperation.java @@ -80,9 +80,8 @@ public class GetAliasOperation extends RemoteOperation> { } } catch (Exception e) { - e.printStackTrace(); result = new RemoteOperationResult<>(e); - Timber.tag(GetAliasOperation.class.getSimpleName()).d("Fetching aliases failed"); + Timber.d(e, "Fetching aliases failed"); } finally { if (get != null) get.releaseConnection(); @@ -95,7 +94,7 @@ public class GetAliasOperation extends RemoteOperation> { public JSONArray parseResponse(@NonNull String response) { JSONArray result = null; try { - final JSONObject jsonResponse= new JSONObject(response).optJSONObject(NODE_OCS); + final JSONObject jsonResponse = new JSONObject(response).optJSONObject(NODE_OCS); if (jsonResponse == null) return result; final JSONObject jsonData = jsonResponse.optJSONObject(NODE_DATA); @@ -103,7 +102,7 @@ public class GetAliasOperation extends RemoteOperation> { result = jsonData.optJSONArray(NODE_ALIASES); } catch (JSONException e) { - e.printStackTrace(); + Timber.e(e); } return result; } diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java index 5a605ef4..d2d56b46 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -30,6 +30,7 @@ import java.text.StringCharacterIterator; import java.util.Locale; import foundation.e.drive.R; +import timber.log.Timber; import static foundation.e.drive.utils.AppConstants.MEDIA_SYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.METERED_NETWORK_ALLOWED_AUTHORITY; @@ -184,7 +185,7 @@ public abstract class CommonUtils { Method get = c.getMethod("get", String.class); value = (String) get.invoke(c, prop); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); } return value == null ? "" : value; } -- GitLab