From bb2f723bc888f16337b5cfe06a6429698c3d047c Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Thu, 8 Nov 2018 10:26:42 +0100 Subject: [PATCH] Add Log.Level translation from Log's priorities --- .../nordicsemi/android/log/LogContract.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/log/src/main/java/no/nordicsemi/android/log/LogContract.java b/log/src/main/java/no/nordicsemi/android/log/LogContract.java index decfc2f..82aa6cc 100644 --- a/log/src/main/java/no/nordicsemi/android/log/LogContract.java +++ b/log/src/main/java/no/nordicsemi/android/log/LogContract.java @@ -168,7 +168,7 @@ public static Uri createUri(final String key, final int number) { *
  • {@link #ERROR}
  • * */ - public final class Level { + public final static class Level { /** * Level used just for debugging purposes. It has the lowest importance level. */ @@ -197,6 +197,35 @@ public final class Level { private Level() { // empty } + + /** + * The Log {@link Level} and {@link android.util.Log} are not compatible. + * Level has additional {@link #APPLICATION} level, while Log the + * {@link android.util.Log#ASSERT}. Also, the {@link android.util.Log#WARN} has + * the same value as {@link #INFO}. Therefore, a translation needs to be done to + * log a message using {@link android.util.Log} priorities. + * + * @param priority the {@link android.util.Log} priority. + * @return the {@link Level} matching given priority. + */ + public static int fromPriority(final int priority) { + switch (priority) { + case android.util.Log.VERBOSE: + return LogContract.Log.Level.VERBOSE; + case android.util.Log.DEBUG: + return LogContract.Log.Level.DEBUG; + case android.util.Log.INFO: + return LogContract.Log.Level.INFO; + case android.util.Log.WARN: + return LogContract.Log.Level.WARNING; + case android.util.Log.ERROR: + case android.util.Log.ASSERT: + return LogContract.Log.Level.ERROR; + default: + // In case the Level was used, for example APPLICATION. + return priority; + } + } } }