Add setting to enable TRACE log level

This commit is contained in:
José Rebelo
2026-05-16 18:48:03 +01:00
parent 4761716bea
commit c1d8fce4d3
5 changed files with 32 additions and 2 deletions
@@ -237,7 +237,10 @@ public class GBApplication extends Application {
GBDatabaseManager.setupDatabase(this); 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(); migratePrefsIfNeeded();
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder; import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.ILoggingEvent;
@@ -57,8 +58,9 @@ public class Logging {
return INSTANCE; return INSTANCE;
} }
public void initialize(final boolean enable) { public void initialize(final boolean enable, final boolean trace) {
setFileLoggingEnabled(enable); setFileLoggingEnabled(enable);
setTraceLogging(trace);
// prepare for log shutdown // prepare for log shutdown
if (!initialized) { if (!initialized) {
final Thread thread = new Thread(this::shutdown, "shutdownHook"); final Thread thread = new Thread(this::shutdown, "shutdownHook");
@@ -136,6 +138,15 @@ public class Logging {
return logDirectory != null; 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() { public void debugLoggingConfiguration() {
// For debugging problems with the logback configuration // For debugging problems with the logback configuration
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
@@ -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); pref = findPreference(PREF_LANGUAGE);
+2
View File
@@ -2638,6 +2638,8 @@
<string name="error_background_service_reason_truncated">Starting the background service failed because…</string> <string name="error_background_service_reason_truncated">Starting the background service failed because…</string>
<string name="pref_crash_notification_title">Notify on crash</string> <string name="pref_crash_notification_title">Notify on crash</string>
<string name="pref_crash_notification_summary">When the app crashes, display a notification with the error</string> <string name="pref_crash_notification_summary">When the app crashes, display a notification with the error</string>
<string name="pref_log_level_trace_title">Trace logging</string>
<string name="pref_log_level_trace_summary">Increase logging level to TRACE</string>
<string name="app_crash_notification_title">%1s has crashed</string> <string name="app_crash_notification_title">%1s has crashed</string>
<string name="app_crash_share_stacktrace">Share error</string> <string name="app_crash_share_stacktrace">Share error</string>
<string name="device_is_currently_bonded">ALREADY BONDED</string> <string name="device_is_currently_bonded">ALREADY BONDED</string>
+7
View File
@@ -407,6 +407,13 @@
android:layout="@layout/preference_checkbox" android:layout="@layout/preference_checkbox"
android:title="@string/pref_write_logfiles" android:title="@string/pref_write_logfiles"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="log_level_trace"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_log_level_trace_summary"
android:title="@string/pref_log_level_trace_title"
app:iconSpaceReserved="false" />
<Preference <Preference
android:key="log_restart" android:key="log_restart"
android:summary="@string/pref_restart_logging_summary" android:summary="@string/pref_restart_logging_summary"