This library sends the Logcat log to Fabric Crashlytics when your app crashes. Having more information about a crash is never a bad thing, right?
Yes, you could change all your Log.x()
commands to FirebaseCrashlytics.getInstance().log()
, but that's a waste of time.
Also, what about system logs or third-party libraries which you can not change? This library fixes this problem.
Add the following dependency to your build.gradle:
dependencies {
compile 'cat.ereza:logcatreporter:1.4.0'
}
On your application class, use this snippet:
@Override
public void onCreate() {
super.onCreate();
//Initialize the LogcatReporter
LogcatReporter.install();
}
If you are using any UncaughtExceptionHandler
, please ensure that is is initialized before installing LogcatReporter.
Make the app crash by using something like this in your code:
throw new RuntimeException("Boom!");
A new Crashlytics issue should appear, and should show the application log if you go to the issue details.
You can report non-fatal crashes to Firebase Crashlytics with the Logcat log attached by using LogcatReporter.reportExceptionWithLogcat(Throwable)
instead of Crashlytics.logException(Throwable)
.
You can provide additional parameters to the install()
method, they are the following:
lineCount
: Maximum lines of Logcat output to send to Crashlytics. The default value is 1000.waitTimeInMillis
: Time that the library will wait for the process to send the log to Crashlytics. Don't set it too high because this blocks the main thread. The default value is 500.
No need to add special rules, the library should work even with obfuscation.
This library relies on the Thread.setDefaultUncaughtExceptionHandler
method.
When an exception is caught by the library's UncaughtExceptionHandler
it does the following:
- Read the Logcat for the application
- Log it to Firebase Crashlytics via
FirebaseCrashlytics.getInstance().log()
- Execute the next
UncaughtExceptionHandler
in the chain (normally the one from Firebase Crashlytics)
- There is a small possibility that this might stop working on newer Firebase Crashlytics SDKs.
- There is no guarantee that this will work on every device (hint: it doesn't!)
- This library will not make you toast for breakfast :)
Any contribution in order to make this library better will be welcome!
The library is licensed under the Apache License 2.0.