-
-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sentry Android does not capture LogCat logs #1620
Comments
Thanks for raising @fzyzcjy. Last we looked at this it wasn't as straight forward as something like Timber. We'll do another investigation. Do you have suggestions on how to implement this and/or is willing to make a PR to add support? |
@bruno-garcia I also do not have quite good solutions. If there is an idea I can make a PR. In addition, it is not possible to let every library use Timber. For example, one third party library may print out some Log.w or Log.e which I want to capture and recognize (because it can be the cause of some bugs), but it is not possible now :( However, IMHO this is a very useful feature! |
Now that we have attachment support it makes more sense to look into logcat again. It actually came up here: #1615 If you're willing to discuss it would be nice to discuss ideas. @marandaneto I'm sure will have opinions here btw. Very high level it would be nice to have an options: |
@bruno-garcia Interested in the suggestion! |
it'd be possible ootb only via bytecode manipulation or executing |
@marandaneto @bruno-garcia I realize this is REALLY VERY VERY useful, when I am debugging today. I am debugging a third party sdk, and finally one useful clue is found by examing system logcat. without using logcat to see what the 3rd party library logs out, I cannot find any useful clue. |
We can execute |
Sounds great! Will it require extra permission or slow down the app - inside release app builds? |
It does, but not for all versions apparently. https://github.com/pedrovgs/Lynx/blob/7b1f25172f2bd3f4563076dcd58ec532aebfb9f1/sample/src/main/AndroidManifest.xml#L20-L21 |
Aha, that is for android 2.x if the comments are right. Then almost nobody is using 2.x :) |
Use code below to upload logcat including native crash happened fun initSentry(context: Context, dsn: String) {
SentryAndroid.init(context) {
it.dsn = dsn
it.tracesSampleRate = 0.03
it.addEventProcessor(object: EventProcessor {
override fun process(event: SentryEvent, hint: Any?): SentryEvent? {
Runtime.getRuntime().exec("logcat -t 1000 *:I").inputStream.use { input ->
context.openFileOutput("logcat.txt", MODE_PRIVATE).use { out ->
input.copyTo(out)
}
}
return super.process(event, hint)
}
})
it.isEnableScopeSync = true
}
Sentry.configureScope { scope ->
scope.addAttachment(
Attachment(
context.filesDir.path + "/logcat.txt",
"logcat.txt", "text/plain"
)
)
}
} |
https://developer.android.com/studio/preview/features#logcat Not sure if the logcat output has changed or the IDE is parsing it, but worth checking it when working on this issue, worst case we have to parse 2 formats. |
I suspect we can reuse this logcat parser from the Android framework itself |
What approach would be most helpful - having breadcrumbs per log entry (only selected/filtered logs), having logs attached to crashes, or perhaps allowing both options? |
More options looks more flexible IMHO. If possible, it would be the best to make this a library or a separate module, such that I can even gather those logcat logs and send to my own logging infra (e.g. when there is no crash but has warnings so I would like to have a look) |
Having done our first feasibility checks (looking good! 🚀 ) we have a few options on how logs are collected and displayed on sentry.io B) Collecting the logs as breadcrumbs I'm wondering if there are more options or even providing both could make sense. @kyze8439690 @fzyzcjy it would be great to get your thoughts on this to help us shape this feature! |
@markushi Congratulations on the checks! I personally prefer the former, since the latter is very limited in length. In addition, I wonder whether it will be provided as a separate easy-to-use module? Then, for example, I can add a few lines ( |
I don't think we should raise error events because we'd not have stack traces anyway (making it less useful?). Using a file requires constant The question is to try it out and check how verbose it is, compare the trade-offs and decide based on user experience. |
We have transferred the logcat file to the sentry as an attachment. After describing the file type as 'text/plain', sentry can directly view the file content in text form on the web page without additional file download. |
I also tend to go for the first solution since we use breadcrumbs to log user behavior instead of app logs. |
@kyze8439690 did you check on which Android versions your code running |
Sorry, we didn't do a complete compatibility test because the logcat file upload is not for end users. But I think it is acceptable to support only API level 23 and above. |
We've shipped this. See https://docs.sentry.io/platforms/android/configuration/integrations/logcat/ |
How many lines of logcat can be recorded right now? |
Our logcat integration only includes creating breadcrumbs out of logs with a specified If you still want to log the last n number of logs as an attachment you can still do that as you currently do by adding an |
Is there a way to manual install Logcat Integration? I don't want to install with the Sentry Android Gradle Plugin. @buenaflor |
@kasogg You would have to manually replace all of your We can reconsider though, if there's a good usecase. Are you fine with manually replacing the log calls? We could make it officially public. |
My requirement is:
I find a workaround:
|
@kasogg ok, it's a bit different usecase from what we have implemented, you can open up a new issue if you will and we'll see if it gets more demand we might eventually implement it, but for now I'd suggest you stick to your own solution. thanks |
@romtsn This was the initial proposed solution but it only works for API level >= 23, that's why we opted for the bytecode manipulation route |
Platform:
IDE:
Build system:
Android Gradle Plugin:
Sentry Android Gradle Plugin:
Proguard/R8:
Platform installed with:
The version of the SDK:
3.x.x
I have the following issue:
The description goes here ...
Steps to reproduce:
Actual result:
Sentry Android does not capture LogCat logs
Expected result:
when having things like
Log.i(...)
, I hope sentry can automatically capture it.thank you!
The text was updated successfully, but these errors were encountered: