mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Add setting to enable TRACE log level
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
+7
@@ -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);
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user