Last active
February 24, 2016 22:51
-
-
Save ccabanero/9b7b955c5ae2d9a9472a to your computer and use it in GitHub Desktop.
Android-ErrorReporting-Rollbar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sample code for using Rollbar to report run-time exceptions ... | |
| public class ErrorReporter { | |
| public static void initializeErrorLogging(Context context) { | |
| Rollbar.init(context, Configuration.ROLLBAR_CLIENT_SIDE_TOKEN, Configuration.ROLLBAR_DEPLOYMENT_STATUS); | |
| } | |
| /** | |
| * For creating a string that will parse the class name, method name, and line of code for the passed in stack trace element | |
| * @param stackTraceElement The stack trace element on the thread where an exception was thrown | |
| * @return Returns a string with the class name, method name, and line of code | |
| */ | |
| private static String fetchStackTraceDetails(StackTraceElement stackTraceElement) { | |
| String stackTraceDetails = ". Class: " + stackTraceElement.getClassName(); | |
| stackTraceDetails += "; Method: " + stackTraceElement.getMethodName(); | |
| stackTraceDetails += "; Line: " + String.valueOf(stackTraceElement.getLineNumber()); | |
| return stackTraceDetails; | |
| } | |
| /** | |
| * For reporting an error to Rollbar | |
| * @param throwable The throwable (e.g. Exception) | |
| * @param stackTraceElement The StackTraceElement on the associated thread to allow us to fetch the Class name, Method name, and line number where exception occurred | |
| * @param errorLevel The error level (e.g. critical, warning, info, or debug) | |
| */ | |
| public static void report(Throwable throwable, StackTraceElement stackTraceElement, String errorLevel) { | |
| String message = throwable.getMessage(); | |
| message += ErrorReporter.fetchStackTraceDetails(stackTraceElement); | |
| Rollbar.reportException(throwable, errorLevel, message); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment