pedrovgs / Lynx

Lynx is an Android library created to show a custom view with all the information Android logcat is printing, different traces of different levels will be rendererd to show from log messages to your application exceptions. You can filter this traces, share your logcat to other apps, configure the max number of traces to show or the sampling rate used by the library.
Apache License 2.0
780 stars 94 forks source link

Toast rather than crash when sharing giant traces #31

Closed stkent closed 7 years ago

stkent commented 7 years ago

Fixes #25.

@pedrovgs unlike #30, there are several fairly different ways this issue could be addressed. I've included one in this PR, but am more than happy to discuss and make changes if you'd prefer a different solution. (For example, we could build an automatic retry with truncated traces into the shareTraces method.)

pedrovgs commented 7 years ago

Hi @stkent, sorry for the late response.

I think this implementation good but we should not show an error to the user if the trace is too long. We should measure the max trace size taking a look at the original implementation and don't try to send more traces than the one we can share depending on the OS version. What do you think? Can we update this PR implementing this change?

stkent commented 7 years ago

I'm not sure there's a known per-Intent limit available for us to read at runtime (see e.g. http://stackoverflow.com/questions/12496700/maximum-length-of-intent-putextra-method-force-close). The empirical "type-then-catch-the-exception" method is a way of working around that uncertainty. If you know something I don't, however, please point me to a reference in the docs!

pedrovgs commented 7 years ago

After researching this issue seems that there is a limit depending on the Android SDK being used and device close to 1 MB of bytes being sent using a Parcelable instance.

Here you have some references:

Based on this information, I'd catch the exception and if the limit is exceeded we should try to share just the last 100kb of traces. Even when the limit seems to be 1MB there is a blog post saying that it could be closer to 500kb so I think the last 100kb should be enough information. What do you think @stkent? Can we update this PR implementing this behavior?

stkent commented 7 years ago

Awesome, yes, I think that behavior should be possible! I'll try today and let you know how it goes :)

pedrovgs commented 7 years ago

Great! Let me know once the code is ready and I'll take a look again 😃

stkent commented 7 years ago

@pedrovgs let me know what you think of the updated suggestion!

pedrovgs commented 7 years ago

Great @stkent! Thank you so much for your time and patience 😃 I'm merging this PR and releasing a new version!

stkent commented 7 years ago

No problem, thanks for maintaining a great library!

pedrovgs commented 7 years ago

I've just released the new version!