From dabeef829e3579e6cce4df4ea4741291035315e5 Mon Sep 17 00:00:00 2001 From: DESKTOP-FE3E8CL-JeeFo Date: Mon, 16 Jul 2018 20:04:25 +0100 Subject: [PATCH] #14 Update Readme * Spotted and fixed logcat minlevel issue * Updated readme to give the new version and to use the builder --- README.md | 10 +++++--- .../jeefo/android/logger/MainActivity.java | 3 +++ .../android/jeefologger/FinalLogger.java | 24 +++++++++---------- .../android/jeefologger/JeefoLogger.java | 3 ++- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e8c4ece..4ed1c86 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,15 @@ dependencies { ``` ## Initializing LazyLogger and Persistence -**In order to use LazyLogger and/or to persist the logs, you must initilize them. This needs doing only once.** +**In order to use LazyLogger and/or to persist the logs, you must initilize them. This needs doing only once using the JeeFoLogger builder. (This is not required unless you want to use persistence, lazylogger or to set the minimum logcat logging level different than VERBOSE)** ```groovy -JeefoLogger.initPersistence(this); -JeefoLogger.initLazyLogger(context); +new JeefoLogger.Builder(context) + .withPersistence(true) // default is false + .withLazyLogger(true) // default is false + .withMinimumLogcatLevel(LogLevel.VERBOSE) // default is LogLevel.VERBOSE + .withMinimumPersistenceLevel(LogLevel.VERBOSE) // default is LogLevel.VERBOSE (this line will not do anything unless withPeristence(true) is used) + .buildAndInit(); ``` You must provide an Android `context`. A good place to initialize them is in `onCreate` on an application subclass: diff --git a/example/src/main/java/com/jeefo/android/logger/MainActivity.java b/example/src/main/java/com/jeefo/android/logger/MainActivity.java index 1f90733..dd99439 100644 --- a/example/src/main/java/com/jeefo/android/logger/MainActivity.java +++ b/example/src/main/java/com/jeefo/android/logger/MainActivity.java @@ -22,6 +22,7 @@ import com.jeefo.android.jeefologger.ILog; import com.jeefo.android.jeefologger.JeefoLogger; +import com.jeefo.android.jeefologger.LogLevel; import com.jeefo.android.jeefologger.SmartLoggerFactory; import com.jeefo.android.logger.utils.LazyLoggerDemonstrationUtils; import com.jeefo.android.logger.utils.OnMyExampleEventListener; @@ -64,6 +65,8 @@ protected void onCreate(Bundle savedInstanceState) { new JeefoLogger.Builder(this) .withPersistence(true) .withLazyLogger(true) + .withMinimumLogcatLevel(LogLevel.VERBOSE) + .withMinimumPersistenceLevel(LogLevel.VERBOSE) .buildAndInit(); // To fetch the log files at any point, use the following. This method currently works only after buildAndInit() but this will change in a future version diff --git a/jeefologger/src/main/java/com/jeefo/android/jeefologger/FinalLogger.java b/jeefologger/src/main/java/com/jeefo/android/jeefologger/FinalLogger.java index 34babd9..2ac8b44 100644 --- a/jeefologger/src/main/java/com/jeefo/android/jeefologger/FinalLogger.java +++ b/jeefologger/src/main/java/com/jeefo/android/jeefologger/FinalLogger.java @@ -15,7 +15,7 @@ public class FinalLogger implements IInternalLog { static final String TAG_LOGGING_PREFIX = "[JeeFo-Log]"; @LogLevel - static int persistenceMinLevel = LogLevel.VERBOSE; + static int logcatMinLevel = LogLevel.VERBOSE; private static final ILog persistentLogger = PersistentLogger.getInstance(); @@ -40,7 +40,7 @@ private FinalLogger() { @Override public void InternalVerbose(@Nullable LinkedList traceElements, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(null, messageToLog, args); - if (persistenceMinLevel <= LogLevel.VERBOSE) { + if (logcatMinLevel <= LogLevel.VERBOSE) { Log.v(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Verbose(finalMessage); @@ -49,7 +49,7 @@ public void InternalVerbose(@Nullable LinkedList traceElement @Override public void InternalVerbose(@Nullable LinkedList traceElements, Exception exception, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(exception, messageToLog, args); - if (persistenceMinLevel <= LogLevel.VERBOSE) { + if (logcatMinLevel <= LogLevel.VERBOSE) { Log.v(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Verbose(finalMessage); @@ -58,7 +58,7 @@ public void InternalVerbose(@Nullable LinkedList traceElement @Override public void InternalDebug(@Nullable LinkedList traceElements, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(null, messageToLog, args); - if (persistenceMinLevel <= LogLevel.DEBUG) { + if (logcatMinLevel <= LogLevel.DEBUG) { Log.d(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Debug(finalMessage); @@ -67,7 +67,7 @@ public void InternalDebug(@Nullable LinkedList traceElements, @Override public void InternalDebug(@Nullable LinkedList traceElements, Exception exception, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(exception, messageToLog, args); - if (persistenceMinLevel <= LogLevel.DEBUG) { + if (logcatMinLevel <= LogLevel.DEBUG) { Log.d(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Debug(finalMessage); @@ -76,7 +76,7 @@ public void InternalDebug(@Nullable LinkedList traceElements, @Override public void InternalInfo(@Nullable LinkedList traceElements, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(null, messageToLog, args); - if (persistenceMinLevel <= LogLevel.INFO) { + if (logcatMinLevel <= LogLevel.INFO) { Log.i(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Info(finalMessage); @@ -85,7 +85,7 @@ public void InternalInfo(@Nullable LinkedList traceElements, @Override public void InternalWarn(@Nullable LinkedList traceElements, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(null, messageToLog, args); - if (persistenceMinLevel <= LogLevel.WARN) { + if (logcatMinLevel <= LogLevel.WARN) { Log.w(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Warn(finalMessage); @@ -94,7 +94,7 @@ public void InternalWarn(@Nullable LinkedList traceElements, @Override public void InternalWarn(@Nullable LinkedList traceElements, Exception exception, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(exception, messageToLog, args); - if (persistenceMinLevel <= LogLevel.WARN) { + if (logcatMinLevel <= LogLevel.WARN) { Log.w(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Warn(finalMessage); @@ -103,7 +103,7 @@ public void InternalWarn(@Nullable LinkedList traceElements, @Override public void InternalError(@Nullable LinkedList traceElements, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(null, messageToLog, args); - if (persistenceMinLevel <= LogLevel.ERROR) { + if (logcatMinLevel <= LogLevel.ERROR) { Log.e(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Error(finalMessage); @@ -112,7 +112,7 @@ public void InternalError(@Nullable LinkedList traceElements, @Override public void InternalError(@Nullable LinkedList traceElements, Exception exception, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(exception, messageToLog, args); - if (persistenceMinLevel <= LogLevel.ERROR) { + if (logcatMinLevel <= LogLevel.ERROR) { Log.e(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Error(finalMessage); @@ -121,7 +121,7 @@ public void InternalError(@Nullable LinkedList traceElements, @Override public void InternalWtf(@Nullable LinkedList traceElements, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(null, messageToLog, args); - if (persistenceMinLevel <= LogLevel.WTF) { + if (logcatMinLevel <= LogLevel.WTF) { Log.wtf(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Wtf(finalMessage); @@ -130,7 +130,7 @@ public void InternalWtf(@Nullable LinkedList traceElements, S @Override public void InternalWtf(@Nullable LinkedList traceElements, Exception exception, String messageToLog, Object... args) { String finalMessage = getFormattedMessage(exception, messageToLog, args); - if (persistenceMinLevel <= LogLevel.WTF) { + if (logcatMinLevel <= LogLevel.WTF) { Log.wtf(TAG_LOGGING_PREFIX + PersistentTagsManager.getTagsStringPrefix(), finalMessage); } persistentLogger.Wtf(finalMessage); diff --git a/jeefologger/src/main/java/com/jeefo/android/jeefologger/JeefoLogger.java b/jeefologger/src/main/java/com/jeefo/android/jeefologger/JeefoLogger.java index b7ad03d..1da52d6 100644 --- a/jeefologger/src/main/java/com/jeefo/android/jeefologger/JeefoLogger.java +++ b/jeefologger/src/main/java/com/jeefo/android/jeefologger/JeefoLogger.java @@ -217,7 +217,8 @@ public void buildAndInit() { final Context context = appContextWeakReference.get(); if (context != null) { - FinalLogger.persistenceMinLevel = minPersistenceLevel; + + FinalLogger.logcatMinLevel = minLogcatLevel; if (useLazyLogger) { LazyLogger.packageName = context.getPackageName();