Skip to content

Commit

Permalink
refactor: Log statements only for debuggable build types
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushiknsanji committed Nov 9, 2019
1 parent 2b7ea78 commit 1f9526e
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.data.local.models.Product;
import com.example.kaushiknsanji.storeapp.data.local.models.ProductImage;
import com.example.kaushiknsanji.storeapp.data.local.models.ProductLite;
import com.example.kaushiknsanji.storeapp.data.local.models.ProductSupplierSales;
import com.example.kaushiknsanji.storeapp.data.local.models.Supplier;
import com.example.kaushiknsanji.storeapp.data.local.models.SupplierContact;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -493,7 +493,7 @@ public void deleteImageFilesSilently(List<String> fileContentUriList) {
public void onSuccess(Boolean results) {
//no-op
//Just logging the result
Log.i(LOG_TAG, "onSuccess: deleteImageFilesSilently: All Image files deleted");
Logger.i(LOG_TAG, "onSuccess: deleteImageFilesSilently: All Image files deleted");
}

/**
Expand All @@ -507,7 +507,7 @@ public void onSuccess(Boolean results) {
public void onFailure(int messageId, @Nullable Object... args) {
//no-op
//Just logging the failure
Log.i(LOG_TAG, "onFailure: deleteImageFilesSilently: Some Image files were not deleted");
Logger.i(LOG_TAG, "onFailure: deleteImageFilesSilently: Some Image files were not deleted");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
import android.text.TextUtils;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.data.local.contracts.ProductContract;
import com.example.kaushiknsanji.storeapp.data.local.contracts.SalesContract;
import com.example.kaushiknsanji.storeapp.data.local.contracts.StoreContract;
import com.example.kaushiknsanji.storeapp.data.local.contracts.SupplierContract;
import com.example.kaushiknsanji.storeapp.data.local.utils.QueryArgsUtility;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import static com.example.kaushiknsanji.storeapp.data.local.utils.SqliteUtility.AND;
import static com.example.kaushiknsanji.storeapp.data.local.utils.SqliteUtility.EQUALS;
Expand Down Expand Up @@ -965,7 +965,7 @@ private Uri insertWithConflictFail(Uri uri, String tableName, SQLiteDatabase wri
//Validating the operation
if (recordId == -1) {
//Logging the error when insertion fails
Log.e(LOG_TAG, "insertWithConflictFail: " + tableName + ": Failed to insert row for " + uri);
Logger.e(LOG_TAG, "insertWithConflictFail: " + tableName + ": Failed to insert row for " + uri);
} else {
//On success of inserting the record

Expand All @@ -981,11 +981,11 @@ private Uri insertWithConflictFail(Uri uri, String tableName, SQLiteDatabase wri
}
} catch (SQLiteConstraintException e) {
//Can occur if the inserted record already exists
Log.e(LOG_TAG, "insertWithConflictFail: " + tableName + ": Record already exists for " + uri, e);
Logger.e(LOG_TAG, "insertWithConflictFail: " + tableName + ": Record already exists for " + uri, e);
} catch (SQLException e) {
//For an error in SQL string or any other unknown causes
//Logging the error
Log.e(LOG_TAG, "insertWithConflictFail: " + tableName + ": Failed to insert row for " + uri, e);
Logger.e(LOG_TAG, "insertWithConflictFail: " + tableName + ": Failed to insert row for " + uri, e);
}

//Returning the URI generated for the record inserted
Expand Down Expand Up @@ -1298,7 +1298,7 @@ private boolean insertBulkRecord(Uri uri, String tableName, SQLiteDatabase writa
//Validating the operation
if (recordId == -1) {
//Logging the error when insertion fails
Log.e(LOG_TAG, "insertBulkRecord: " + tableName + ": Failed to insert row for " + uri);
Logger.e(LOG_TAG, "insertBulkRecord: " + tableName + ": Failed to insert row for " + uri);
//Returning False on Failure
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQuery;
import android.os.Build;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.data.local.contracts.ProductContract.Product;
import com.example.kaushiknsanji.storeapp.data.local.contracts.ProductContract.ProductAttribute;
Expand All @@ -38,6 +37,7 @@
import com.example.kaushiknsanji.storeapp.data.local.contracts.SupplierContract.SupplierContactType;
import com.example.kaushiknsanji.storeapp.utils.AppConstants;
import com.example.kaushiknsanji.storeapp.utils.AppExecutors;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import static com.example.kaushiknsanji.storeapp.data.local.utils.SqliteUtility.CLOSE_BRACE;
import static com.example.kaushiknsanji.storeapp.data.local.utils.SqliteUtility.COMMA;
Expand Down Expand Up @@ -322,10 +322,10 @@ private void insertPredefinedCategories() {
if (noOfRecordsInserted == preloadedCategories.length) {
//When all categories are inserted successfully, mark the transaction as successful
writableDatabase.setTransactionSuccessful();
Log.i(LOG_TAG, "insertPredefinedCategories: Predefined Categories inserted");
Logger.i(LOG_TAG, "insertPredefinedCategories: Predefined Categories inserted");
} else {
//When NOT all categories are inserted, log the error
Log.e(LOG_TAG, "insertPredefinedCategories: Predefined Categories failed to insert.");
Logger.e(LOG_TAG, "insertPredefinedCategories: Predefined Categories failed to insert.");
}

//Releasing the lock in the end
Expand Down Expand Up @@ -387,10 +387,10 @@ private void insertPredefinedContactTypes() {
if (noOfRecordsInserted == noOfContactTypes) {
//When all contact types are inserted successfully, mark the transaction as successful
writableDatabase.setTransactionSuccessful();
Log.i(LOG_TAG, "insertPredefinedContactTypes: Predefined Contact types inserted");
Logger.i(LOG_TAG, "insertPredefinedContactTypes: Predefined Contact types inserted");
} else {
//When NOT all contact types are inserted, log the error
Log.e(LOG_TAG, "insertPredefinedContactTypes: Predefined Contact types failed to insert.");
Logger.e(LOG_TAG, "insertPredefinedContactTypes: Predefined Contact types failed to insert.");
}

//Releasing the lock in the end
Expand Down Expand Up @@ -498,8 +498,8 @@ public Cursor newCursor(SQLiteDatabase db,

//Log the Query when logging is enabled
if (AppConstants.LOG_CURSOR_QUERIES) {
Log.i(LOG_TAG, "Table: " + editTable);
Log.i(LOG_TAG, "newCursor: " + query.toString());
Logger.i(LOG_TAG, "Table: " + editTable);
Logger.i(LOG_TAG, "newCursor: " + query.toString());
}

//Returning the SQLiteCursor instance for the query fired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.R;
import com.example.kaushiknsanji.storeapp.data.FileRepository;
import com.example.kaushiknsanji.storeapp.utils.AppExecutors;
import com.example.kaushiknsanji.storeapp.utils.FileStorageUtility;
import com.example.kaushiknsanji.storeapp.utils.ImageStorageUtility;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void saveImageToFile(Context context, Uri fileContentUri, FileOperationsC
//Saving the Image to a file and retrieving its Content URI
savedImageFileUri = ImageStorageUtility.saveImage(context, fileContentUri);
} catch (IOException e) {
Log.e(LOG_TAG, "saveImageToFile: Error occurred while saving the image " + fileContentUri, e);
Logger.e(LOG_TAG, "saveImageToFile: Error occurred while saving the image " + fileContentUri, e);
}

//Saves the URI to pass the result to the callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.R;
import com.example.kaushiknsanji.storeapp.data.DataRepository;
Expand All @@ -45,6 +44,7 @@
import com.example.kaushiknsanji.storeapp.ui.inventory.config.SalesConfigActivity;
import com.example.kaushiknsanji.storeapp.ui.products.config.ProductConfigActivity;
import com.example.kaushiknsanji.storeapp.utils.AppConstants;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -738,7 +738,7 @@ private void triggerNotification(Uri uri) {
if (mDeliveredNotification.compareAndSet(false, true)) {
//When notification was not delivered previously, dispatch the notification and set to TRUE

Log.i(LOG_TAG, "triggerNotification: Called for " + uri);
Logger.i(LOG_TAG, "triggerNotification: Called for " + uri);

//Posting notification on Main Thread
mMainThreadHandler.post(SalesListPresenter.this::onContentChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.R;
import com.example.kaushiknsanji.storeapp.data.DataRepository;
Expand All @@ -35,6 +34,7 @@
import com.example.kaushiknsanji.storeapp.ui.products.config.DefaultPhotoChangeListener;
import com.example.kaushiknsanji.storeapp.ui.products.config.ProductConfigActivity;
import com.example.kaushiknsanji.storeapp.ui.suppliers.config.SupplierConfigActivity;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -339,7 +339,7 @@ public void updateProductImage(ArrayList<ProductImage> productImages) {
//This case should not occur, since at least one image needs to be selected.

//Logging the error
Log.e(LOG_TAG, "ERROR!!! updateProductImages: Product Images found but no default image");
Logger.e(LOG_TAG, "ERROR!!! updateProductImages: Product Images found but no default image");

//Delegating to the listener to show the Default Image
mDefaultPhotoChangeListener.showDefaultImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.R;
import com.example.kaushiknsanji.storeapp.data.DataRepository;
Expand All @@ -42,6 +41,7 @@
import com.example.kaushiknsanji.storeapp.data.local.models.ProductLite;
import com.example.kaushiknsanji.storeapp.ui.products.config.ProductConfigActivity;
import com.example.kaushiknsanji.storeapp.utils.AppConstants;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -578,7 +578,7 @@ private void triggerNotification(Uri uri) {
if (mDeliveredNotification.compareAndSet(false, true)) {
//When notification was not delivered previously, dispatch the notification and set to TRUE

Log.i(LOG_TAG, "triggerNotification: Called for " + uri);
Logger.i(LOG_TAG, "triggerNotification: Called for " + uri);

//Posting notification on Main Thread
mMainThreadHandler.post(ProductListPresenter.this::onContentChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.support.annotation.StringRes;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.R;
import com.example.kaushiknsanji.storeapp.data.DataRepository;
Expand All @@ -31,6 +30,7 @@
import com.example.kaushiknsanji.storeapp.data.local.models.ProductAttribute;
import com.example.kaushiknsanji.storeapp.data.local.models.ProductImage;
import com.example.kaushiknsanji.storeapp.ui.products.image.ProductImageActivity;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -407,7 +407,7 @@ public void updateProductImages(ArrayList<ProductImage> productImages) {
//This case should not occur, since at least one image needs to be selected.

//Logging the error
Log.e(LOG_TAG, "ERROR!!! updateProductImages: Product Images found but no default image");
Logger.e(LOG_TAG, "ERROR!!! updateProductImages: Product Images found but no default image");

//Delegating to the listener to show the Default Image
mDefaultPhotoChangeListener.showDefaultImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -59,6 +58,7 @@
import com.example.kaushiknsanji.storeapp.ui.common.ProgressDialogFragment;
import com.example.kaushiknsanji.storeapp.utils.FileStorageUtility;
import com.example.kaushiknsanji.storeapp.utils.ImageStorageUtility;
import com.example.kaushiknsanji.storeapp.utils.Logger;
import com.example.kaushiknsanji.storeapp.utils.OrientationUtility;
import com.example.kaushiknsanji.storeapp.utils.SnackbarUtility;
import com.example.kaushiknsanji.storeapp.workers.ImageDownloaderFragment;
Expand Down Expand Up @@ -644,7 +644,7 @@ private void dispatchTakePictureIntent() {
try {
tempPhotoFile = ImageStorageUtility.createTempImageFile(requireContext());
} catch (IOException e) {
Log.e(LOG_TAG, "dispatchTakePictureIntent: Error occurred while creating a temp file ", e);
Logger.e(LOG_TAG, "dispatchTakePictureIntent: Error occurred while creating a temp file ", e);
}

//When the Temp file is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.util.Log;

import com.example.kaushiknsanji.storeapp.R;
import com.example.kaushiknsanji.storeapp.data.DataRepository;
Expand All @@ -42,6 +41,7 @@
import com.example.kaushiknsanji.storeapp.data.local.models.SupplierLite;
import com.example.kaushiknsanji.storeapp.ui.suppliers.config.SupplierConfigActivity;
import com.example.kaushiknsanji.storeapp.utils.AppConstants;
import com.example.kaushiknsanji.storeapp.utils.Logger;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -642,7 +642,7 @@ private void triggerNotification(Uri uri) {
if (mDeliveredNotification.compareAndSet(false, true)) {
//When notification was not delivered previously, dispatch the notification and set to TRUE

Log.i(LOG_TAG, "triggerNotification: Called for " + uri);
Logger.i(LOG_TAG, "triggerNotification: Called for " + uri);

//Posting notification on Main Thread
mMainThreadHandler.post(SupplierListPresenter.this::onContentChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ private AppConstants() {

//Constant used for the CursorLoader to load the list of Products for Selling from the database
public static final int SALES_LOADER = 3;

//Constant for the Debug Build Type flag
public static final boolean DEBUG = BuildConfig.DEBUG;
}
Loading

0 comments on commit 1f9526e

Please sign in to comment.