Log/persist refactoring

This commit is contained in:
M66B 2021-10-22 15:04:16 +02:00
parent e4bb6e183e
commit aced841156
3 changed files with 12 additions and 19 deletions

View File

@ -190,7 +190,6 @@ public class ApplicationEx extends Application
if (Helper.hasWebView(this))
CookieManager.getInstance().setAcceptCookie(false);
TrafficStatsHelper.init(this);
EncryptionHelper.init(this);
MessageHelper.setSystemProperties(this);

View File

@ -138,6 +138,8 @@ import javax.net.ssl.SSLPeerUnverifiedException;
import io.requery.android.database.CursorWindowAllocationException;
public class Log {
private static Context ctx;
private static int level = android.util.Log.INFO;
private static final int MAX_CRASH_REPORTS = 5;
private static final String TAG = "fairemail";
@ -286,6 +288,13 @@ public class Log {
return android.util.Log.e(TAG, prefix + " " + ex + "\n" + android.util.Log.getStackTraceString(ex));
}
public static void persist(String message) {
if (ctx == null)
Log.e(message);
else
EntityLog.log(ctx, message);
}
static void setCrashReporting(boolean enabled) {
try {
if (enabled)
@ -319,6 +328,7 @@ public class Log {
}
static void setup(Context context) {
ctx = context;
setLevel(context);
setupBugsnag(context);
}

View File

@ -19,28 +19,12 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
public class TrafficStatsHelper {
private static Context ctx;
static void init(Context context) {
ctx = context;
}
public static void connect(String host, int port, String prefix) {
String msg = "Connected " + prefix + " " + host + ":" + port;
if (ctx == null)
Log.i(msg);
else
EntityLog.log(ctx, EntityLog.Type.Statistics, msg);
Log.persist("Connected " + prefix + " " + host + ":" + port);
}
public static void report(String host, String prefix, long sent, long received) {
String msg = "Disconnected " + prefix + " " + host + " tx=" + sent + " rx=" + received;
if (ctx == null)
Log.i(msg);
else
EntityLog.log(ctx, EntityLog.Type.Statistics, msg);
Log.persist("Disconnected " + prefix + " " + host + " tx=" + sent + " rx=" + received);
}
}