|
|
@ -25,55 +25,74 @@ import android.content.SharedPreferences;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
|
|
import org.tinylog.Level;
|
|
|
|
import org.tinylog.Level;
|
|
|
|
import org.tinylog.configuration.PropertiesConfigurationLoader;
|
|
|
|
import org.tinylog.core.TinylogLoggingProvider;
|
|
|
|
|
|
|
|
import org.tinylog.format.MessageFormatter;
|
|
|
|
|
|
|
|
import org.tinylog.provider.ProviderRegistry;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://tinylog.org/v2/configuration/
|
|
|
|
// https://tinylog.org/v2/configuration/
|
|
|
|
// https://github.com/tinylog-org/tinylog-android-example/blob/v2/app/src/main/resources/tinylog.properties
|
|
|
|
// https://github.com/tinylog-org/tinylog-android-example/blob/v2/app/src/main/resources/tinylog.properties
|
|
|
|
|
|
|
|
|
|
|
|
public class TinyLogConfigurationLoader extends PropertiesConfigurationLoader {
|
|
|
|
public class FairEmailLoggingProvider extends TinylogLoggingProvider {
|
|
|
|
private static Level level = Level.TRACE;
|
|
|
|
private Level activeLevel = Level.WARN;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setLevel(Level level) {
|
|
|
|
|
|
|
|
activeLevel = level;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean isEnabled(int depth, String tag, Level level) {
|
|
|
|
|
|
|
|
return (activeLevel.ordinal() <= level.ordinal() &&
|
|
|
|
|
|
|
|
super.isEnabled(depth + 1, tag, level));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Properties load() {
|
|
|
|
public void log(int depth, String tag, Level level, Throwable exception, MessageFormatter formatter, Object obj, Object... arguments) {
|
|
|
|
Properties props = super.load();
|
|
|
|
if (activeLevel.ordinal() <= level.ordinal())
|
|
|
|
props.setProperty("level", level.name());
|
|
|
|
super.log(depth, tag, level, exception, formatter, obj, arguments);
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void log(String loggerClassName, String tag, Level level, Throwable exception, MessageFormatter formatter, Object obj, Object... arguments) {
|
|
|
|
|
|
|
|
if (activeLevel.ordinal() <= level.ordinal())
|
|
|
|
|
|
|
|
super.log(loggerClassName, tag, level, exception, formatter, obj, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setup(Context context) {
|
|
|
|
static void setup(Context context) {
|
|
|
|
|
|
|
|
System.setProperty("tinylog.directory",
|
|
|
|
|
|
|
|
new File(context.getFilesDir(), "logs").getAbsolutePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setLevel(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void setLevel(Context context) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
boolean debug = prefs.getBoolean("debug", false); // Changing requires force stop
|
|
|
|
boolean debug = prefs.getBoolean("debug", false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FairEmailLoggingProvider provider = (FairEmailLoggingProvider) ProviderRegistry.getLoggingProvider();
|
|
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
if (debug)
|
|
|
|
level = Level.DEBUG;
|
|
|
|
provider.activeLevel = Level.DEBUG;
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
int def = (BuildConfig.DEBUG || BuildConfig.TEST_RELEASE ? android.util.Log.INFO : android.util.Log.WARN);
|
|
|
|
int def = (BuildConfig.DEBUG || BuildConfig.TEST_RELEASE ? android.util.Log.INFO : android.util.Log.WARN);
|
|
|
|
int _level = prefs.getInt("log_level", def);
|
|
|
|
int _level = prefs.getInt("log_level", def);
|
|
|
|
if (_level == android.util.Log.VERBOSE)
|
|
|
|
if (_level == android.util.Log.VERBOSE)
|
|
|
|
level = Level.TRACE;
|
|
|
|
provider.activeLevel = Level.TRACE;
|
|
|
|
else if (_level == android.util.Log.DEBUG)
|
|
|
|
else if (_level == android.util.Log.DEBUG)
|
|
|
|
level = Level.DEBUG;
|
|
|
|
provider.activeLevel = Level.DEBUG;
|
|
|
|
else if (_level == android.util.Log.INFO)
|
|
|
|
else if (_level == android.util.Log.INFO)
|
|
|
|
level = Level.INFO;
|
|
|
|
provider.activeLevel = Level.INFO;
|
|
|
|
else if (_level == android.util.Log.WARN)
|
|
|
|
else if (_level == android.util.Log.WARN)
|
|
|
|
level = Level.WARN;
|
|
|
|
provider.activeLevel = Level.WARN;
|
|
|
|
else if (_level == android.util.Log.ERROR)
|
|
|
|
else if (_level == android.util.Log.ERROR)
|
|
|
|
level = Level.ERROR;
|
|
|
|
provider.activeLevel = Level.ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
System.setProperty("tinylog.configurationloader",
|
|
|
|
|
|
|
|
TinyLogConfigurationLoader.class.getName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.setProperty("tinylog.directory",
|
|
|
|
|
|
|
|
new File(context.getFilesDir(), "logs").getAbsolutePath());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static File[] getFiles(Context context) {
|
|
|
|
static File[] getLogFiles(Context context) {
|
|
|
|
File[] files = new File(context.getFilesDir(), "logs").listFiles();
|
|
|
|
File[] files = new File(context.getFilesDir(), "logs").listFiles();
|
|
|
|
|
|
|
|
|
|
|
|
if (files == null)
|
|
|
|
if (files == null)
|