This library sends the Logcat log to 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 Crashlytics.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.0.0'
}
On your application class, use this snippet:
@Override
public void onCreate() {
super.onCreate();
//Initialize Crashlytics as normal (you probably already have this code)
Fabric.with(this, new Crashlytics());
//Initialize the LogcatReporter
LogcatReporter.install();
}
WARNING! You MUST install LogcatReporter AFTER initializing Crashlytics. If you don't, it will not work.
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 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 Crashlytics via
Crashlytics.log()
- Execute the next
UncaughtExceptionHandler
in the chain (normally the one from Crashlytics)
On API<16, you will get no logs reported by default. If you really want to report logs from those devices,
you must declare the READ_LOGS
permission on your manifest. We do not recommend enabling this since it can expose user private information or data from other apps.
- There is a small possibility that this might stop working on newer 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.