mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Merge branch '1428-android-debug-logging' into 'master'
Enable debug logging for debug and beta builds Closes #1428 See merge request briar/briar!1154
This commit is contained in:
@@ -37,6 +37,7 @@ import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREG
|
|||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.logging.Level.FINE;
|
import static java.util.logging.Level.FINE;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.acra.ReportField.ANDROID_VERSION;
|
import static org.acra.ReportField.ANDROID_VERSION;
|
||||||
import static org.acra.ReportField.APP_VERSION_CODE;
|
import static org.acra.ReportField.APP_VERSION_CODE;
|
||||||
import static org.acra.ReportField.APP_VERSION_NAME;
|
import static org.acra.ReportField.APP_VERSION_NAME;
|
||||||
@@ -82,7 +83,7 @@ public class BriarApplicationImpl extends Application
|
|||||||
implements BriarApplication {
|
implements BriarApplication {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BriarApplicationImpl.class.getName());
|
getLogger(BriarApplicationImpl.class.getName());
|
||||||
|
|
||||||
private final CachingLogHandler logHandler = new CachingLogHandler();
|
private final CachingLogHandler logHandler = new CachingLogHandler();
|
||||||
private final BackgroundMonitor backgroundMonitor = new BackgroundMonitor();
|
private final BackgroundMonitor backgroundMonitor = new BackgroundMonitor();
|
||||||
@@ -108,12 +109,16 @@ public class BriarApplicationImpl extends Application
|
|||||||
|
|
||||||
if (IS_DEBUG_BUILD) enableStrictMode();
|
if (IS_DEBUG_BUILD) enableStrictMode();
|
||||||
|
|
||||||
Logger rootLogger = Logger.getLogger("");
|
Logger rootLogger = getLogger("");
|
||||||
if (!IS_DEBUG_BUILD && !IS_BETA_BUILD) {
|
Handler[] handlers = rootLogger.getHandlers();
|
||||||
// Remove default log handlers so system log is not used
|
// Disable the Android logger for release builds
|
||||||
for (Handler handler : rootLogger.getHandlers()) {
|
for (Handler handler : handlers) rootLogger.removeHandler(handler);
|
||||||
rootLogger.removeHandler(handler);
|
if (IS_DEBUG_BUILD || IS_BETA_BUILD) {
|
||||||
}
|
// We can't set the level of the Android logger at runtime, so
|
||||||
|
// raise records to the logger's default level
|
||||||
|
rootLogger.addHandler(new LevelRaisingHandler(FINE, INFO));
|
||||||
|
// Restore the default handlers after the level raising handler
|
||||||
|
for (Handler handler : handlers) rootLogger.addHandler(handler);
|
||||||
}
|
}
|
||||||
rootLogger.addHandler(logHandler);
|
rootLogger.addHandler(logHandler);
|
||||||
rootLogger.setLevel(IS_DEBUG_BUILD || IS_BETA_BUILD ? FINE : INFO);
|
rootLogger.setLevel(IS_DEBUG_BUILD || IS_BETA_BUILD ? FINE : INFO);
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.util.logging.Handler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log handler that raises all records at or above a given source level to a
|
||||||
|
* given destination level. This affects the level seen by subsequent handlers.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
class LevelRaisingHandler extends Handler {
|
||||||
|
|
||||||
|
private final Level dest;
|
||||||
|
private final int srcInt, destInt;
|
||||||
|
|
||||||
|
LevelRaisingHandler(Level src, Level dest) {
|
||||||
|
this.dest = dest;
|
||||||
|
srcInt = src.intValue();
|
||||||
|
destInt = dest.intValue();
|
||||||
|
if (srcInt > destInt) throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(LogRecord record) {
|
||||||
|
int recordInt = record.getLevel().intValue();
|
||||||
|
if (recordInt >= srcInt && recordInt < destInt) record.setLevel(dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user