Skip to content

Commit

Permalink
#155: Made seperate logging for MediaImageDbReplacement / FotoSql / C…
Browse files Browse the repository at this point in the history
…ontentprovider
  • Loading branch information
k3b committed Dec 19, 2019
1 parent ea14a12 commit fb9594a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package de.k3b.android.androFotoFinder;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
Expand All @@ -37,6 +38,7 @@
import de.k3b.LibGlobal;
import de.k3b.android.GuiUtil;
import de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader;
import de.k3b.android.androFotoFinder.queries.ContentProviderMediaImpl;
import de.k3b.android.androFotoFinder.queries.DatabaseHelper;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.FotoSqlBase;
Expand Down Expand Up @@ -155,7 +157,10 @@ public static RefWatcher getRefWatcher(Context context) {
mCrashSaveToFile = new LogCat(Global.LOG_CONTEXT, HugeImageLoader.LOG_TAG,
PhotoViewAttacher.LOG_TAG, CupcakeGestureDetector.LOG_TAG,
LibGlobal.LOG_TAG, ThumbNailUtils.LOG_TAG, IMapView.LOGTAG,
ExifInterface.LOG_TAG, PhotoPropertiesImageReader.LOG_TAG) {
ExifInterface.LOG_TAG, PhotoPropertiesImageReader.LOG_TAG,
FotoSql.LOG_TAG,
MediaImageDbReplacement.LOG_TAG,
ContentProviderMediaImpl.LOG_TAG) {

@Override
public void uncaughtException(Thread thread, Throwable ex) {
Expand All @@ -165,13 +170,14 @@ public void uncaughtException(Thread thread, Throwable ex) {
super.uncaughtException(thread, ex);
}

public void saveToFile() {
public void saveToFile(Activity activity) {
final File logFile = getOutpuFile();
String message = (logFile != null)
? "saving errorlog ('LocCat') to " + logFile.getAbsolutePath()
: "Saving errorlog ('LocCat') is disabled. See Settings 'Diagnostics' for details";
Log.e(Global.LOG_CONTEXT, message);
Toast.makeText(AndroFotoFinderApp.this , message, Toast.LENGTH_LONG).show();
final Context context = (activity != null) ? activity : AndroFotoFinderApp.this;
Toast.makeText(context, message, Toast.LENGTH_LONG).show();

saveLogCat(logFile, null, mTags);
}
Expand Down Expand Up @@ -226,9 +232,9 @@ public void onTerminate() {
super.onTerminate();
}

public void saveToFile() {
public void saveToFile(Activity activity) {
if (mCrashSaveToFile != null) {
mCrashSaveToFile.saveToFile();
mCrashSaveToFile.saveToFile(activity);
}
}
public void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private void onDebugClearLogCat() {

private void onDebugSaveLogCat() {
Log.e(Global.LOG_CONTEXT, "SettingsActivity-SaveLogCat(): " + ActivityWithCallContext.readCallContext(getIntent()));
((AndroFotoFinderApp) getApplication()).saveToFile();
((AndroFotoFinderApp) getApplication()).saveToFile(this);
}

private void onTranslate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* Static Implementation of Context.getContentResolver()-ContentProvider based media api
*/
public class ContentProviderMediaImpl {
public static final String LOG_TAG = FotoSql.LOG_TAG + "Content";
private static final String MODUL_NAME = ContentProviderMediaImpl.class.getName();

public static Cursor createCursorForQuery(
Expand Down Expand Up @@ -82,7 +83,7 @@ static Cursor createCursorForQuery(
QueryParameter.toString(sqlSelectColums, null, from, sqlWhereStatement,
sqlWhereParameters, sqlSortOrder, query.getCount()));
if (out_debugMessage == null) {
Log.i(Global.LOG_CONTEXT, message.toString(), excpetion);
Log.i(LOG_TAG, message.toString(), excpetion);
} // else logging is done by caller
}
}
Expand All @@ -108,7 +109,7 @@ public static int exexUpdateImpl(String dbgContext, Context context, ContentValu
excpetion = ex;
} finally {
if ((excpetion != null) || ((dbgContext != null) && (Global.debugEnabledSql || LibGlobal.debugEnabledJpg))) {
Log.i(Global.LOG_CONTEXT, dbgContext + ":" +
Log.i(LOG_TAG, dbgContext + ":" +
MODUL_NAME +
".exexUpdate " + excpetion + "\n" +
QueryParameter.toString(null, values.toString(), FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
Expand Down Expand Up @@ -155,7 +156,7 @@ public static Uri execInsert(String dbgContext, Context context, ContentValues v
excpetion = ex;
} finally {
if ((excpetion != null) || Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
Log.i(Global.LOG_CONTEXT, dbgContext + ":" +
Log.i(LOG_TAG, dbgContext + ":" +
MODUL_NAME +
".execInsert " + excpetion + " " +
values.toString() + " => " + result + " " + excpetion, excpetion);
Expand Down Expand Up @@ -187,7 +188,7 @@ public static int deleteMedia(String dbgContext, Context context, String where,
delCount = context.getContentResolver()
.delete(FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs);
if (Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
Log.i(Global.LOG_CONTEXT, dbgContext + "-b: " +
Log.i(LOG_TAG, dbgContext + "-b: " +
MODUL_NAME +
".deleteMedia delete\n" +
QueryParameter.toString(null, null, FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
Expand All @@ -197,7 +198,7 @@ public static int deleteMedia(String dbgContext, Context context, String where,
delCount = context.getContentResolver()
.delete(FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs);
if (Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
Log.i(Global.LOG_CONTEXT, dbgContext + ": " +
Log.i(LOG_TAG, dbgContext + ": " +
MODUL_NAME +
".deleteMedia\ndelete " +
QueryParameter.toString(null, null,
Expand All @@ -213,7 +214,7 @@ public static int deleteMedia(String dbgContext, Context context, String where,
QueryParameter.toString(null, null, FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
lastUsedWhereClause, lastSelectionArgs, null, -1)
+ " : " + ex.getMessage();
Log.e(Global.LOG_CONTEXT, msg, ex);
Log.e(LOG_TAG, msg, ex);

}
return delCount;
Expand Down Expand Up @@ -262,7 +263,7 @@ private static int _del_execRenameFolder_batch_not_working(Context context, Stri
.build());
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, dbgContext + "-getAffected error :", ex);
Log.e(LOG_TAG, dbgContext + "-getAffected error :", ex);
return -1;
} finally {
if (c != null) c.close();
Expand All @@ -273,7 +274,7 @@ private static int _del_execRenameFolder_batch_not_working(Context context, Stri
} catch (Exception ex) {
// java.lang.IllegalArgumentException: Unknown authority content://media/external/file
// i assume not batch support for file
Log.e(Global.LOG_CONTEXT, dbgContext + "-updateAffected error :", ex);
Log.e(LOG_TAG, dbgContext + "-updateAffected error :", ex);
return -1;
}
return ops.size();
Expand All @@ -291,7 +292,7 @@ public static ContentValues getDbContent(Context context, final long id) {
return values;
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, MODUL_NAME +
Log.e(LOG_TAG, MODUL_NAME +
".getDbContent(id=" + id + ") failed", ex);
} finally {
if (c != null) c.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* Created by k3b on 04.06.2015.
*/
public class FotoSql extends FotoSqlBase {
public static final String LOG_TAG = Global.LOG_CONTEXT + "-sql";

public static final int SORT_BY_DATE_OLD = 1;
public static final int SORT_BY_NAME_OLD = 2;
Expand Down Expand Up @@ -298,7 +299,7 @@ public static final double getGroupFactor(final double _zoomLevel) {
}

if (Global.debugEnabled) {
Log.e(Global.LOG_CONTEXT, "FotoSql.getGroupFactor(" + _zoomLevel + ") => " + result);
Log.e(FotoSql.LOG_TAG, "FotoSql.getGroupFactor(" + _zoomLevel + ") => " + result);
}

return result;
Expand Down Expand Up @@ -632,7 +633,7 @@ public static QueryParameter getQuery(int queryID) {
case QUERY_TYPE_GROUP_MOVE:
return null;
default:
Log.e(Global.LOG_CONTEXT, "FotoSql.getQuery(" + queryID + "): unknown ID");
Log.e(FotoSql.LOG_TAG, "FotoSql.getQuery(" + queryID + "): unknown ID");
return null;
}
}
Expand Down Expand Up @@ -757,7 +758,7 @@ public static boolean set(GalleryFilterParameter dest, String selectedAbsolutePa
return true;
default:break;
}
Log.e(Global.LOG_CONTEXT, "FotoSql.setFilter(queryTypeId = " + queryTypeId + ") : unknown type");
Log.e(FotoSql.LOG_TAG, "FotoSql.setFilter(queryTypeId = " + queryTypeId + ") : unknown type");

return false;
}
Expand All @@ -777,7 +778,7 @@ public static String execGetFotoPath(Uri uriWithID) {
return DBUtils.getString(c,FotoSql.SQL_COL_PATH, null);
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.execGetFotoPath() Cannot get path from " + uriWithID, ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.execGetFotoPath() Cannot get path from " + uriWithID, ex);
} finally {
if (c != null) c.close();
}
Expand All @@ -803,13 +804,13 @@ public static List<String> execGetFotoPaths(String pathFilter) {
result.add(c.getString(0));
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.execGetFotoPaths() Cannot get path from: " + FotoSql.SQL_COL_PATH + " like '" + pathFilter +"'", ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.execGetFotoPaths() Cannot get path from: " + FotoSql.SQL_COL_PATH + " like '" + pathFilter + "'", ex);
} finally {
if (c != null) c.close();
}

if (Global.debugEnabled) {
Log.d(Global.LOG_CONTEXT, "FotoSql.execGetFotoPaths() result count=" + result.size());
Log.d(FotoSql.LOG_TAG, "FotoSql.execGetFotoPaths() result count=" + result.size());
}
return result;
}
Expand Down Expand Up @@ -852,13 +853,13 @@ public static IGeoRectangle execGetGeoRectangle(StringBuilder out_debugMessage,
return result;
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.execGetGeoRectangle(): error executing " + query, ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.execGetGeoRectangle(): error executing " + query, ex);
} finally {
if (c != null) c.close();
if (debugMessage != null) {
StringUtils.appendMessage(debugMessage, "result", result);
if (out_debugMessage == null) {
Log.i(Global.LOG_CONTEXT, debugMessage.toString());
Log.i(FotoSql.LOG_TAG, debugMessage.toString());
}
}
}
Expand Down Expand Up @@ -893,13 +894,13 @@ public static IGeoPoint execGetPosition(StringBuilder out_debugMessage,
return result;
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.execGetPosition: error executing " + query, ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.execGetPosition: error executing " + query, ex);
} finally {
if (c != null) c.close();
if (debugMessage != null) {
StringUtils.appendMessage(debugMessage, "result", result);
if (out_debugMessage == null) {
Log.i(Global.LOG_CONTEXT, debugMessage.toString());
Log.i(FotoSql.LOG_TAG, debugMessage.toString());
} // else logging by caller
}
}
Expand Down Expand Up @@ -927,7 +928,7 @@ public static Map<String, Long> execGetPathIdMap(String... fileNames) {
result.put(c.getString(1),c.getLong(0));
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.execGetPathIdMap: error executing " + query, ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.execGetPathIdMap: error executing " + query, ex);
} finally {
if (c != null) c.close();
}
Expand Down Expand Up @@ -1062,7 +1063,7 @@ public static Long getId(Uri uriWithId) {
try {
imageID = (idString == null) ? null : Long.valueOf(idString);
} catch (NumberFormatException e) {
Log.e(Global.LOG_CONTEXT, "FotoSql.getId(" + uriWithId + ") => " + e.getMessage());
Log.e(FotoSql.LOG_TAG, "FotoSql.getId(" + uriWithId + ") => " + e.getMessage());
}
}
return imageID;
Expand Down Expand Up @@ -1106,7 +1107,7 @@ public static String getMinFolder(QueryParameter query,
return c.getString(0);
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.getMinFolder() error :", ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.getMinFolder() error :", ex);
} finally {
if (c != null) c.close();
}
Expand All @@ -1125,7 +1126,7 @@ public static long getCount(QueryParameter query) {
return c.getLong(0);
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.getCount() error :", ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.getCount() error :", ex);
} finally {
if (c != null) c.close();
}
Expand Down Expand Up @@ -1172,7 +1173,7 @@ public static CharSequence getStatisticsMessage(Context context, int prefixStrin
);
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.getStatisticsMessage() error :", ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.getStatisticsMessage() error :", ex);
} finally {
if (c != null) c.close();
}
Expand Down Expand Up @@ -1200,13 +1201,13 @@ private static SelectedFiles getSelectedfiles(QueryParameter query, String colna

result = new SelectedFiles(paths, ids, null);
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.getSelectedfiles() error :", ex);
Log.e(FotoSql.LOG_TAG, "FotoSql.getSelectedfiles() error :", ex);
} finally {
if (c != null) c.close();
}

if (Global.debugEnabled) {
Log.d(Global.LOG_CONTEXT, "FotoSql.getSelectedfiles result count=" + ((result != null) ? result.size():0));
Log.d(FotoSql.LOG_TAG, "FotoSql.getSelectedfiles result count=" + ((result != null) ? result.size() : 0));
}

return result;
Expand Down
Loading

0 comments on commit fb9594a

Please sign in to comment.