finer log level controls
This commit is contained in:
parent
81d71abe39
commit
fb9ed51f52
8 changed files with 82 additions and 38 deletions
|
|
@ -10,8 +10,10 @@ public class Logger {
|
|||
return LEVEL <= Log.DEBUG;
|
||||
}
|
||||
|
||||
public static void enableDebugLevel(boolean yes) {
|
||||
LEVEL = yes ? Log.DEBUG : Log.ERROR;
|
||||
public static void setLevel(int level) {
|
||||
if (level >= Log.VERBOSE && level <= Log.ASSERT) {
|
||||
LEVEL = level;
|
||||
}
|
||||
}
|
||||
|
||||
static public void v(String tag, String msg) {
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
protected void onInit() {
|
||||
self = this;
|
||||
Logger.enableDebugLevel(settings.getDebugLogsEnabled());
|
||||
Logger.setLevel(settings.getLogLevel());
|
||||
|
||||
WordStoreAsync.init(this);
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
|||
|
||||
|
||||
protected void onStart(InputConnection connection, EditorInfo field) {
|
||||
Logger.enableDebugLevel(settings.getDebugLogsEnabled());
|
||||
Logger.setLevel(settings.getLogLevel());
|
||||
|
||||
setInputField(connection, field);
|
||||
initTyping();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class PreferencesActivity extends AppCompatActivity implements Preference
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
settings = new SettingsStore(this);
|
||||
applyTheme();
|
||||
Logger.enableDebugLevel(settings.getDebugLogsEnabled());
|
||||
Logger.setLevel(settings.getLogLevel());
|
||||
|
||||
try (LegacyDb db = new LegacyDb(this)) { db.clear(); }
|
||||
WordStoreAsync.init(this);
|
||||
|
|
|
|||
|
|
@ -270,7 +270,13 @@ public class SettingsStore {
|
|||
|
||||
/************* internal settings *************/
|
||||
|
||||
public boolean getDebugLogsEnabled() { return prefs.getBoolean("pref_enable_debug_logs", Logger.isDebugLevel()); }
|
||||
public int getLogLevel() {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString("pref_log_level", String.valueOf(Logger.LEVEL)));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return Logger.LEVEL;
|
||||
}
|
||||
}
|
||||
|
||||
public final static int DICTIONARY_IMPORT_BATCH_SIZE = 5000; // words
|
||||
public final static int DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME = 250; // ms
|
||||
|
|
|
|||
|
|
@ -48,12 +48,10 @@ public class ItemDropDown {
|
|||
}
|
||||
|
||||
public ItemDropDown enableClickHandler() {
|
||||
if (item == null) {
|
||||
Logger.w("SectionKeymap.populateItem", "Cannot set a click listener a NULL item. Ignoring.");
|
||||
return this;
|
||||
if (item != null) {
|
||||
item.setOnPreferenceChangeListener(this::onClick);
|
||||
}
|
||||
|
||||
item.setOnPreferenceChangeListener(this::onClick);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -74,11 +72,20 @@ public class ItemDropDown {
|
|||
}
|
||||
}
|
||||
|
||||
public void preview() {
|
||||
public ItemDropDown preview() {
|
||||
try {
|
||||
setPreview(values.get(Integer.parseInt(item.getValue())));
|
||||
} catch (Exception e) {
|
||||
setPreview("");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemDropDown setValue(String value) {
|
||||
if (item != null) {
|
||||
item.setValue(value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package io.github.sspanak.tt9.preferences.items;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import io.github.sspanak.tt9.Logger;
|
||||
|
||||
public class ItemLogLevel extends ItemDropDown {
|
||||
public static final String NAME = "pref_log_level";
|
||||
|
||||
public ItemLogLevel(DropDownPreference item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
public ItemLogLevel populate() {
|
||||
LinkedHashMap<Integer, String> values = new LinkedHashMap<>();
|
||||
values.put(Log.VERBOSE, "Verbose");
|
||||
values.put(Log.DEBUG, "Debug");
|
||||
values.put(Log.INFO, "Info");
|
||||
values.put(Log.WARN, "Warning");
|
||||
values.put(Log.ERROR, "Error (default)");
|
||||
|
||||
super.populate(values);
|
||||
super.setValue(String.valueOf(Logger.LEVEL));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onClick(Preference preference, Object newKey) {
|
||||
if (super.onClick(preference, newKey)) {
|
||||
Logger.setLevel(Integer.parseInt(newKey.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,11 +15,11 @@ import java.io.InputStreamReader;
|
|||
import io.github.sspanak.tt9.Logger;
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||
import io.github.sspanak.tt9.preferences.items.ItemLogLevel;
|
||||
import io.github.sspanak.tt9.ui.UI;
|
||||
|
||||
public class DebugScreen extends BaseScreenFragment {
|
||||
private final static String LOG_TAG = "DebugScreen";
|
||||
private final static String DEBUG_LOGS_SWITCH = "pref_enable_debug_logs";
|
||||
private final static String SYSTEM_LOGS_SWITCH = "pref_enable_system_logs";
|
||||
private final static String LOGS_CONTAINER = "debug_logs_container";
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ public class DebugScreen extends BaseScreenFragment {
|
|||
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
initLogMessagesSwitch();
|
||||
intiLogLevelDropDown();
|
||||
initSystemLogsSwitch();
|
||||
enableLogsCopy();
|
||||
|
||||
|
|
@ -40,32 +40,19 @@ public class DebugScreen extends BaseScreenFragment {
|
|||
printLogs(includeSystemLogs);
|
||||
}
|
||||
|
||||
private void initLogMessagesSwitch() {
|
||||
SwitchPreferenceCompat msgSwitch = findPreference(DEBUG_LOGS_SWITCH);
|
||||
if (msgSwitch == null) {
|
||||
Logger.w(LOG_TAG, "Debug logs switch not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
msgSwitch.setChecked(Logger.isDebugLevel());
|
||||
msgSwitch.setOnPreferenceChangeListener((Preference p, Object newValue) -> {
|
||||
Logger.enableDebugLevel((boolean) newValue);
|
||||
return true;
|
||||
});
|
||||
private void intiLogLevelDropDown() {
|
||||
(new ItemLogLevel(findPreference(ItemLogLevel.NAME))).populate().preview().enableClickHandler();
|
||||
}
|
||||
|
||||
private void initSystemLogsSwitch() {
|
||||
SwitchPreferenceCompat systemLogs = findPreference(SYSTEM_LOGS_SWITCH);
|
||||
if (systemLogs == null) {
|
||||
Logger.w(LOG_TAG, "System logs switch not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (systemLogs != null) {
|
||||
systemLogs.setOnPreferenceChangeListener((p, newValue) -> {
|
||||
printLogs((boolean) newValue);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void printLogs(boolean includeSystemLogs) {
|
||||
Preference logsContainer = findPreference(LOGS_CONTAINER);
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@
|
|||
app:layout="@layout/pref_text"
|
||||
app:title="@string/pref_category_usage_stats" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:key="pref_enable_debug_logs"
|
||||
app:layout="@layout/pref_switch"
|
||||
app:title="Debug Logs" />
|
||||
<DropDownPreference
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="pref_log_level"
|
||||
app:layout="@layout/pref_dropdown"
|
||||
app:title="Log Level" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue