Skip to content

Commit

Permalink
add loggers instead of e.printStackTrace - #777
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlittle committed Feb 7, 2019
1 parent 9b56c7a commit 19b2ac6
Show file tree
Hide file tree
Showing 39 changed files with 210 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Boolean call() throws Exception {
refreshTagList();
} catch (JSONException e) {
Mint.logException(e);
e.printStackTrace();
Log.d(TAG, "Error conencting to server: ", e);
UIUtils.showAlert(this, R.string.loading, R.string.error_connection, finishActivity);
}
} else {
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/org/digitalcampus/oppia/di/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.oppia.application.DbHelper;
import org.digitalcampus.oppia.application.SessionManager;
Expand All @@ -27,6 +30,8 @@
@Module
public class AppModule {

public static final String TAG = AppModule.class.getSimpleName();

private Application app;

public AppModule(Application app){
Expand Down Expand Up @@ -57,7 +62,8 @@ public User provideUser(){
try {
return DbHelper.getInstance(app).getUser(SessionManager.getUsername(app));
} catch (UserNotFoundException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "User not found: ", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
versionNo.setText(getString(R.string.version,no));
} catch (NameNotFoundException e) {
Mint.logException(e);
e.printStackTrace();
Log.d(TAG, "Error getting version name: ", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ private void refreshBadgesList() {
tv.setVisibility(View.GONE);
badgesAdapter.notifyDataSetChanged();
} catch (Exception e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "Error refreshing badges list: ", e);
}

}
Expand All @@ -129,7 +130,7 @@ public void apiRequestComplete(Payload response) {
} catch (JSONException e) {
Mint.logException(e);
UIUtils.showAlert(super.getActivity(), R.string.loading, R.string.error_connection);
e.printStackTrace();
Log.d(TAG, "Error connecting to server: ", e);
}
} else {
TextView tv = (TextView) this.getView().findViewById(R.id.fragment_badges_title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.preference.PreferenceManager;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.mobile.quiz.Quiz;
import org.digitalcampus.oppia.activity.PrefsActivity;
import org.digitalcampus.oppia.application.DbHelper;
Expand Down Expand Up @@ -179,7 +181,8 @@ else if (SERVICE_EVENT_MEDIAPLAYBACK.equals(eventName)){
}
}
} catch (JSONException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "JSON error: ", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;

import com.splunk.mint.Mint;

public class Activity implements Serializable{

Expand Down Expand Up @@ -188,7 +191,8 @@ public void setContentFromJSONString(String json){
}
}
} catch (JSONException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "JSON error: ", e);
}
}
public boolean hasMedia(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.digitalcampus.oppia.model;

import android.content.Context;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.activity.CourseIndexActivity;
Expand All @@ -15,13 +18,16 @@

public class CompleteCourseProvider {

public static final String TAG = CompleteCourseProvider.class.getSimpleName();

public CompleteCourse getCompleteCourseSync(Context ctx, Course course){
try {
CourseXMLReader cxr = new CourseXMLReader(course.getCourseXMLLocation(), course.getCourseId(), ctx);
cxr.parse(CourseXMLReader.ParseMode.COMPLETE);
return cxr.getParsedCourse();
} catch (InvalidXMLException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "Error loading course XML: ", e);
showErrorMessage(ctx);
return null;
}
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/org/digitalcampus/oppia/model/MultiLangInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.digitalcampus.oppia.model;

import android.util.Log;

import com.splunk.mint.Mint;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -28,6 +32,8 @@

public class MultiLangInfo implements Serializable {

public static final String TAG = MultiLangInfo.class.getSimpleName();

private ArrayList<Lang> langs = new ArrayList<>();
private ArrayList<Lang> titles = new ArrayList<>();
private ArrayList<Lang> descriptions = new ArrayList<>();
Expand Down Expand Up @@ -103,7 +109,8 @@ private String getInfoJSONString(ArrayList<Lang> values){
try {
obj.put(l.getLang(), l.getContent());
} catch (JSONException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "JSON error: ", e);
}
array.put(obj);
}
Expand All @@ -128,9 +135,11 @@ private void setInfoFromJSONString(String jsonStr, ArrayList<Lang> values, boole
}
}
} catch (JSONException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "JSON error: ", e);
} catch (NullPointerException npe){
npe.printStackTrace();
Mint.logException(npe);
Log.d(TAG, "Null pointer error: ", npe);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public void apiRequestComplete(Payload response) {
}

} catch (JSONException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "JSON error: ", e);
}

if(updateAvailable){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.support.annotation.Nullable;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.model.CourseTransferableFile;
import org.digitalcampus.oppia.utils.storage.FileUtils;
Expand Down Expand Up @@ -316,7 +318,8 @@ public void sendFile(CourseTransferableFile trFile){
tasksDownloading.remove(trFile);

} catch (IOException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "IO exception: ", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.preference.PreferenceManager;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.activity.PrefsActivity;
import org.digitalcampus.oppia.application.DbHelper;
Expand Down Expand Up @@ -83,8 +85,8 @@ public static void installDownloadedCourse(Context ctx, String filename, String
courseDir = tempdir.list()[0]; // use this to get the course name
} catch (ArrayIndexOutOfBoundsException aioobe) {
FileUtils.cleanUp(tempdir, Storage.getDownloadPath(ctx) + filename);
aioobe.printStackTrace();
Log.d(TAG, "Error: " + aioobe.getMessage());
Mint.logException(aioobe);
Log.d(TAG, "Error: ", aioobe);
listener.onError(ctx.getString(R.string.error_installing_course, shortname));
return;
}
Expand All @@ -100,8 +102,8 @@ public static void installDownloadedCourse(Context ctx, String filename, String
courseTrackerXMLPath = tempdir + File.separator + courseDir + File.separator + MobileLearning.COURSE_TRACKER_XML;
} catch (ArrayIndexOutOfBoundsException aioobe){
FileUtils.cleanUp(tempdir, Storage.getDownloadPath(ctx) + filename);
aioobe.printStackTrace();
Log.d(TAG, "Error: " + aioobe.getMessage());
Mint.logException(aioobe);
Log.d(TAG, "Error: ", aioobe);
listener.onError(ctx.getString(R.string.error_media_download));
return;
}
Expand Down Expand Up @@ -154,7 +156,8 @@ public static void installDownloadedCourse(Context ctx, String filename, String
org.apache.commons.io.FileUtils.copyDirectory(src, new File(dest, src.getName()));
success = true;
} catch (IOException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "Error copying course: ", e);
listener.onFail(ctx.getString(R.string.error_installing_course, title));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private boolean updateCourseSchedule(String scheduleUrl, String shortname){

} catch (JSONException e) {
Mint.logException(e);
e.printStackTrace();
Log.d(TAG, "JSON error: ", e);
sendBroadcast(scheduleUrl, ACTION_FAILED, getString(R.string.error_processing_response));
removeDownloading(scheduleUrl);
} catch (UserNotFoundException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import android.content.Context;
import android.util.Log;

import com.splunk.mint.Mint;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Expand Down Expand Up @@ -74,7 +76,8 @@ protected Payload doInBackground(Payload... params){
}

} catch (IOException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "IO exception", e);
payload.setResult(false);
payload.setResultResponse(ctx.getString(R.string.error_connection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import android.preference.PreferenceManager;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.activity.PrefsActivity;
import org.digitalcampus.oppia.listener.MoveStorageListener;
Expand Down Expand Up @@ -142,8 +144,8 @@ private boolean copyDirectory(String sourcePath, String destPath){
FileUtils.deleteDir(source);
Log.d(TAG,"Copying " + sourcePath + " completed");
} catch (IOException e) {
Log.d(TAG,"Copying " + sourcePath + " to " + destPath + " failed");
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "Copying " + sourcePath + " to " + destPath + " failed", e);
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.text.TextUtils;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.oppia.activity.PrefsActivity;
import org.digitalcampus.oppia.application.DbHelper;
import org.digitalcampus.oppia.listener.ExportActivityListener;
Expand All @@ -29,7 +31,7 @@

public class ExportActivityTask extends AsyncTask<Payload, Integer, String> {

private static final String TAG = ExportActivityTask.class.getSimpleName();;
private static final String TAG = ExportActivityTask.class.getSimpleName();
protected Context ctx;
private SharedPreferences prefs;
private ExportActivityListener listener;
Expand Down Expand Up @@ -106,9 +108,11 @@ protected String doInBackground(Payload... payloads) {
out = new OutputStreamWriter(f);
out.write(json);
} catch (FileNotFoundException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "FileNotFoundException: ", e);
} catch (IOException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "IO exception: ", e);
} finally {
if (out != null){
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.os.AsyncTask;
import android.util.Log;

import com.splunk.mint.Mint;

import org.digitalcampus.mobile.learning.R;
import org.digitalcampus.oppia.application.DbHelper;
import org.digitalcampus.oppia.application.MobileLearning;
Expand All @@ -29,13 +31,13 @@
public class ImportLeaderboardsTask extends AsyncTask<Payload, DownloadProgress, Payload> {


private static final String TAG = ImportLeaderboardsTask.class.getSimpleName();

public interface ImportLeaderboardListener {
void onLeaderboardImportProgress(String message);
void onLeaderboardImportComplete(Boolean success, String message);
}


public final static String TAG = ImportLeaderboardsTask.class.getSimpleName();
private Context ctx;


Expand Down Expand Up @@ -65,13 +67,17 @@ protected Payload doInBackground(Payload... params) {
String json = FileUtils.readFile(json_file);
updatedPositions += Leaderboard.importLeaderboardJSON(ctx, json);
} catch (IOException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "IOException: ", e);
} catch (ParseException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "ParseException: ", e);
} catch (JSONException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "JSONException: ", e);
} catch (WrongServerException e) {
e.printStackTrace();
Mint.logException(e);
Log.d(TAG, "WrongServerException: ", e);
}

FileUtils.deleteFile(json_file);
Expand Down

0 comments on commit 19b2ac6

Please sign in to comment.