mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-10 12:09:27 +01:00
Make file-logging configurable
This commit is contained in:
parent
c469248de1
commit
4518e8819d
@ -10,11 +10,12 @@
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${GB_LOGFILES_DIR}/gadgetbridge.log</file>
|
||||
|
||||
<lazy>true</lazy>
|
||||
<!-- encoders are by default assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>gadgetbridge-%d{yyyy-MM-dd}.log.zip</fileNamePattern>
|
||||
<fileNamePattern>${GB_LOGFILES_DIR}/gadgetbridge-%d{yyyy-MM-dd}.log.zip</fileNamePattern>
|
||||
<maxHistory>10</maxHistory>
|
||||
</rollingPolicy>
|
||||
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||
|
@ -7,7 +7,9 @@ import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -2,6 +2,11 @@ package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -16,23 +21,37 @@ public class GBApplication extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
setupLogFileDir();
|
||||
setupLogging();
|
||||
// For debugging problems with the logback configuration
|
||||
// LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
// print logback's internal status
|
||||
// StatusPrinter.print(lc);
|
||||
// String dataDir = lc.getProperty(CoreConstants.DATA_DIR_KEY);
|
||||
// String filename = FileUtil.prefixRelativePath(dataDir, "gadgetbridge.log");
|
||||
// Logger logger = LoggerFactory.getLogger(GBApplication.class);
|
||||
}
|
||||
|
||||
private void setupLogFileDir() {
|
||||
File dir = getExternalFilesDir(null);
|
||||
if (dir != null && !dir.exists()) {
|
||||
dir.mkdirs();
|
||||
public static boolean isFileLoggingEnabled() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
||||
return prefs.getBoolean(GBApplication.getContext().getString(R.string.pref_log_to_file), false);
|
||||
}
|
||||
|
||||
private void setupLogging() {
|
||||
if (isFileLoggingEnabled()) {
|
||||
File dir = getExternalFilesDir(null);
|
||||
if (dir != null && !dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
// used by assets/logback.xml since the location cannot be statically determined
|
||||
System.setProperty("GB_LOGFILES_DIR", dir.getAbsolutePath());
|
||||
} else {
|
||||
System.setProperty("GB_LOGFILES_DIR", "/dev/null"); // just to please logback configuration, not used at all
|
||||
try {
|
||||
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||
root.detachAppender("FILE");
|
||||
} catch (Throwable ex) {
|
||||
System.out.println("Error removing logger FILE appender");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
// used by assets/logback.xml since the location cannot be statically determined
|
||||
System.setProperty("GB_LOGFILES_DIR", dir.getAbsolutePath());
|
||||
}
|
||||
|
||||
public static Context getContext() {
|
||||
|
@ -101,5 +101,7 @@
|
||||
<string name="pref_header_vibration_count">Vibration Count</string>
|
||||
|
||||
<string name="title_activity_sleepmonitor">Sleep Monitor</string>
|
||||
<string name="pref_log_to_file">LogToFile</string>
|
||||
<string name="pref_write_logfiles">Write Log Files (needs restart)</string>
|
||||
|
||||
</resources>
|
||||
|
@ -60,4 +60,10 @@
|
||||
android:key="pref_key_miband"
|
||||
android:title="@string/preferences_miband_settings" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/pref_log_to_file"
|
||||
android:title="@string/pref_write_logfiles" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
Loading…
Reference in New Issue
Block a user