diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 511ca9757d..8d2e6d70ce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -237,7 +237,10 @@ public class GBApplication extends Application { GBDatabaseManager.setupDatabase(this); } - Logging.getInstance().initialize(prefs.getBoolean("log_to_file", false)); + Logging.getInstance().initialize( + prefs.getBoolean("log_to_file", false), + prefs.getBoolean("log_level_trace", false) + ); migratePrefsIfNeeded(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java index dab91df498..4e1781175b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.Locale; +import ch.qos.logback.classic.Level; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.encoder.PatternLayoutEncoder; import ch.qos.logback.classic.spi.ILoggingEvent; @@ -57,8 +58,9 @@ public class Logging { return INSTANCE; } - public void initialize(final boolean enable) { + public void initialize(final boolean enable, final boolean trace) { setFileLoggingEnabled(enable); + setTraceLogging(trace); // prepare for log shutdown if (!initialized) { final Thread thread = new Thread(this::shutdown, "shutdownHook"); @@ -136,6 +138,15 @@ public class Logging { return logDirectory != null; } + public void setTraceLogging(final boolean traceEnabled) { + try { + ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); + root.setLevel(traceEnabled ? Level.TRACE : Level.DEBUG); + } catch (final Throwable e) { + LOG.error("Error changing log level", e); + } + } + public void debugLoggingConfiguration() { // For debugging problems with the logback configuration LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java index ca1b79e884..8c4416ebaa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java @@ -204,6 +204,13 @@ public class SettingsActivity extends AbstractSettingsActivityV2 { }); } } + + final SwitchPreferenceCompat logLevelTrace = findPreference("log_level_trace"); + logLevelTrace.setOnPreferenceChangeListener((preference, newVal) -> { + final boolean traceEnabled = Boolean.TRUE.equals(newVal); + Logging.getInstance().setTraceLogging(traceEnabled); + return true; + }); } pref = findPreference(PREF_LANGUAGE); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bbf99168c7..8ce984cce9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2638,6 +2638,8 @@ Starting the background service failed because… Notify on crash When the app crashes, display a notification with the error + Trace logging + Increase logging level to TRACE %1s has crashed Share error ALREADY BONDED diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index a0f429eb59..42ab196a6f 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -407,6 +407,13 @@ android:layout="@layout/preference_checkbox" android:title="@string/pref_write_logfiles" app:iconSpaceReserved="false" /> +