1
0
mirror of https://github.com/etesync/android synced 2025-01-22 21:51:04 +00:00

Log to file: move to use normal preferences.

This commit is contained in:
Tom Hacohen 2019-03-14 20:30:07 +00:00
parent df315a48ab
commit 1cdad6232e
3 changed files with 5 additions and 22 deletions

View File

@ -40,9 +40,12 @@ object Logger : SharedPreferences.OnSharedPreferenceChangeListener {
val log = java.util.logging.Logger.getLogger("etesync")!! val log = java.util.logging.Logger.getLogger("etesync")!!
private lateinit var context: Context private lateinit var context: Context
private lateinit var preferences: SharedPreferences
fun initialize(someContext: Context) { fun initialize(someContext: Context) {
context = someContext.applicationContext context = someContext.applicationContext
preferences = PreferenceManager.getDefaultSharedPreferences(context)
preferences.registerOnSharedPreferenceChangeListener(this)
reinitialize() reinitialize()
} }
@ -55,10 +58,7 @@ object Logger : SharedPreferences.OnSharedPreferenceChangeListener {
} }
private fun reinitialize() { private fun reinitialize() {
val dbHelper = ServiceDB.OpenHelper(context) val logToFile = preferences.getBoolean(LOG_TO_FILE, false)
val settings = Settings(dbHelper.readableDatabase)
val logToFile = settings.getBoolean(App.LOG_TO_EXTERNAL_STORAGE, false)
val logVerbose = logToFile || Log.isLoggable(Logger.log.name, Log.DEBUG) val logVerbose = logToFile || Log.isLoggable(Logger.log.name, Log.DEBUG)
log.info("Verbose logging: $logVerbose; to file: $logToFile") log.info("Verbose logging: $logVerbose; to file: $logToFile")

View File

@ -44,7 +44,6 @@ class AppSettingsActivity : BaseActivity() {
internal lateinit var prefResetCertificates: Preference internal lateinit var prefResetCertificates: Preference
internal lateinit var prefOverrideProxy: SwitchPreferenceCompat internal lateinit var prefOverrideProxy: SwitchPreferenceCompat
internal lateinit var prefDistrustSystemCerts: SwitchPreferenceCompat internal lateinit var prefDistrustSystemCerts: SwitchPreferenceCompat
internal lateinit var prefLogToExternalStorage: SwitchPreferenceCompat
internal lateinit var prefProxyHost: EditTextPreference internal lateinit var prefProxyHost: EditTextPreference
internal lateinit var prefProxyPort: EditTextPreference internal lateinit var prefProxyPort: EditTextPreference
@ -114,9 +113,6 @@ class AppSettingsActivity : BaseActivity() {
prefResetCertificates = findPreference("reset_certificates") prefResetCertificates = findPreference("reset_certificates")
prefLogToExternalStorage = findPreference("log_to_external_storage") as SwitchPreferenceCompat
prefLogToExternalStorage.isChecked = settings.getBoolean(App.LOG_TO_EXTERNAL_STORAGE, false)
val prefChangeNotification = findPreference("show_change_notification") as SwitchPreferenceCompat val prefChangeNotification = findPreference("show_change_notification") as SwitchPreferenceCompat
prefChangeNotification.isChecked = context!!.defaultSharedPreferences.getBoolean(App.CHANGE_NOTIFICATION, true) prefChangeNotification.isChecked = context!!.defaultSharedPreferences.getBoolean(App.CHANGE_NOTIFICATION, true)
@ -135,8 +131,6 @@ class AppSettingsActivity : BaseActivity() {
setDistrustSystemCerts(preference.isChecked) setDistrustSystemCerts(preference.isChecked)
else if (preference === prefResetCertificates) else if (preference === prefResetCertificates)
resetCertificates() resetCertificates()
else if (preference === prefLogToExternalStorage)
setExternalLogging(preference.isChecked)
else else
return false return false
return true return true
@ -163,17 +157,6 @@ class AppSettingsActivity : BaseActivity() {
Snackbar.make(view!!, getString(R.string.app_settings_reset_certificates_success), Snackbar.LENGTH_LONG).show() Snackbar.make(view!!, getString(R.string.app_settings_reset_certificates_success), Snackbar.LENGTH_LONG).show()
} }
private fun setExternalLogging(externalLogging: Boolean) {
settings.putBoolean(App.LOG_TO_EXTERNAL_STORAGE, externalLogging)
// reinitialize logger of default process
val app = context!!.applicationContext as App
app.reinitLogger()
// reinitialize logger of :sync process
context!!.sendBroadcast(Intent(App.ReinitSettingsReceiver.ACTION_REINIT_SETTINGS))
}
private inner class LanguageTask internal constructor(private val mListPreference: ListPreference) : AsyncTask<Void, Void, LanguageUtils.LocaleList>() { private inner class LanguageTask internal constructor(private val mListPreference: ListPreference) : AsyncTask<Void, Void, LanguageUtils.LocaleList>() {
override fun doInBackground(vararg voids: Void): LanguageUtils.LocaleList { override fun doInBackground(vararg voids: Void): LanguageUtils.LocaleList {

View File

@ -62,7 +62,7 @@
<PreferenceCategory android:title="@string/app_settings_debug"> <PreferenceCategory android:title="@string/app_settings_debug">
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="log_to_external_storage" android:key="log_to_file"
android:title="@string/app_settings_log_to_external_storage" android:title="@string/app_settings_log_to_external_storage"
android:summaryOn="@string/app_settings_log_to_external_storage_on" android:summaryOn="@string/app_settings_log_to_external_storage_on"
android:summaryOff="@string/app_settings_log_to_external_storage_off"/> android:summaryOff="@string/app_settings_log_to_external_storage_off"/>