Skip to content

Commit

Permalink
Add log level to message
Browse files Browse the repository at this point in the history
  • Loading branch information
ypresto committed Nov 11, 2015
1 parent 8c0992c commit 7e23c79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ protected void log(int priority, String tag, String message, Throwable t) {
if (t != null) {
Crashlytics.logException(t);
} else {
String messageWithTag = tag != null ? "[" + tag + "] " + message : message;
Crashlytics.logException(new StackTraceRecorder(messageWithTag));
String formattedMessage = LogMessageHelper.format(priority, tag, message);
Crashlytics.logException(new StackTraceRecorder(formattedMessage));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void log(int priority, String tag, String message, Throwable t) {
return;
}

String messageWithTag = tag != null ? "[" + tag + "] " + message : message;
Crashlytics.log(messageWithTag);
String formattedMessage = LogMessageHelper.format(priority, tag, message);
Crashlytics.log(formattedMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.ypresto.timbertreeutils;

import android.util.Log;

class LogMessageHelper {
public static String format(int priority, String tag, String message) {
String messageWithTag = tag != null ? "[" + tag + "] " + message : message;
return prefixForPriority(priority) + messageWithTag;
}

public static String prefixForPriority(int priority) {
switch (priority) {
case Log.VERBOSE:
return "[VERBOSE] ";
case Log.DEBUG:
return "[DEBUG] ";
case Log.INFO:
return "[INFO] ";
case Log.WARN:
return "[WARN] ";
case Log.ERROR:
return "[ERROR] ";
case Log.ASSERT:
return "[ASSERT] ";
default:
return "[UNKNOWN(" + priority + ")] ";
}
}
}

0 comments on commit 7e23c79

Please sign in to comment.