Clean up printing stack trace call when exception occured
Exception should be logged by calling: Log.e(String, String, Throwable) or some others Log's method.
In the codebase, we have a lot of call to e.printStackTrace(). Those calls should be replaced by the appropriate Log.x methods.
@lognaturel or @yanokwa, do you have preference to do this as separate PR per files or separate commit per file? This could change a lot of files.
@nribeka We've struggled with this kind of change. What's your recommendation?
Initial search showed 158 occurrence of printStackTrace and it's all over the place. Maybe at the minimum we go with separate commits per file? Separating per PR seems to be too much.

To whoever going to do this, don't just do find and replace in the code. You need to read the context of the stacktrace and decide which Log's method will be appropriate. I don't think all should become a Log.e calls.
I was hoping you'd have some kind of magic solution we hadn't thought of! 😉 We need a process because there are a lot of these kinds of issues. A single PR with a commit per file seems ok to me.
I think @batkinson had some opinions on this kind of situation.
And folks who will do this can propose a simplified catch blocks too when we're doing the same thing for each type of exception. One example is the following codes:

Since every catch block treat the exception the same way, there's no benefits of separating it into different blocks.
Can i work on this issue? @nribeka i assume that what you propose in the last message is to combine catch blocks wherever possible like the one you have shown?
@Midhun07 I am working on this issue.
@Midhun07 The real issue is that printStackTrace method has been used everywhere for catching the try blocks. printStaceTrace prints the stack trace in Android Monitor as an error because of the exception caused.
At some places eg. GoogleDriveActivity, this stack trace is not a critical exception so it unneccessarily clutters the error logs.
So instead of calling e.printStackTrace(), relevant Log method Log.d, Log.e, Log.v, Log.w, Log.i should be used. This would help filtering the logs so that relevant logs are not missed.
Also as suggested by @nribeka, multiple catch blocks which are handling the exception exactly the same way should be squashed into one catch block.
@yanokwa @nribeka I stumbled across a great library by Jake Wharton, Timber. A logger with a small, extensible API which provides utility on top of Android's normal Log class. http://jakewharton.github.io/timber/
Pros :
- Development - Logging to logcat
- Production - Crash reporting to Crashlytics
Timber and Crashlytics can be used along with AppCrashHandler which elegently handles unhandled exceptions by restarting the app instead of showing the system dialogs displaying an error has occurred.
Read the article here link
Also addresses #655
Is somebody already assigned on the issue? I am willing to help, we can have only 1 catch block for exceptions wherever necessary.
I have tried my best to justify the task. @nribeka can you please check it in my profile and let me know if I have done something wrong.
@parthuest please submit a pull request as described in the contribution guide.
#663 might actually be a nicer way to address this since it could let us address better logging in both development and production.
Hi, @lognaturel Can i work on this issue ? I am familiar with timber.
Let's break this down to make sure we get it right. It would be good to get a first pull request JUST removing all calls on e.printStackTrace. If you'd like to do that, go ahead and comment and then take it on.
Hi, @lognaturel Can i work on it?
@lognaturel : I can work on it. So basically there will be 2 PR's 1 to just remove all e.printStackTrace and 2nd one to have commits with the appropriate Log.x methods.
@Ishmeetsingh97 Since you know Timber, how about you work on adding a Tree for Firebase Crash and verify that it works.
@anudeepti2004 That's right. Go ahead and do just the removal one. Then once we have @Ishmeetsingh97's Tree ready you can go straight to using Timber methods to do the logging right.
Okay, @lognaturel I will give this a try and let you know my developments.