Skip to content

Commit

Permalink
Add Log.Level translation from Log's priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Nov 8, 2018
1 parent df95de8 commit bb2f723
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion log/src/main/java/no/nordicsemi/android/log/LogContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static Uri createUri(final String key, final int number) {
* <li>{@link #ERROR}</li>
* </ul>
*/
public final class Level {
public final static class Level {
/**
* Level used just for debugging purposes. It has the lowest importance level.
*/
Expand Down Expand Up @@ -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;
}
}
}
}

Expand Down

0 comments on commit bb2f723

Please sign in to comment.