
Log like a pro using a secure logger in Android.
Logging is super useful during and after developing an app. But it could be catastrophic if you are just using the standard Android Log.i/d/e/w methods since you could leak sensitive data of your app.
The most convenient solution is to create a custom logger class that only prints if you are on a debug release. This is not something particularly hard to do; the following is one possible implementation that supports printing of Exceptions as well (useful for try-catch blocks):
Initialization and usage
You can initialize it using the follow line. Just use the same line in every class you want to log things and the simple name of the current class will be used as TAG:
private final Logger logger = Logger.withTag(this.getClass().getSimpleName());
The logger could be especially useful for try-catch blocks where it can print out the whole stack trace of the exception without crashing your app:
try {
// Something that can blow
} catch (Exception ex) {
logger.log("Something went wrong with XYZ.").withCause(ex);
}