Everyone writes logs during project development, as logs are really helpful for debugging applications, displaying exceptions or errors. But this can lead to a headache if you forgot to remove those logs at the end of the project, as many of us don’t want to show our apps API calls and its responses to the world for security reasons. ๐Ÿ™‚

So how can we get rid of these logs during the release of our app?

A clean way to write a solution for the above problem will be,

  1. Use BuildConfig.DEBUG variable – which is automatically generated by the android build, by default set to true which means it is in debug mode and false when you export a release build.
  2. Wrap in helper SimpleLog class which will display logs only when we are debugging.

Let's have a look at how to use these-

First of all, we have to write a custom class like below one

public class SimpleLog{

public static void log(String TAG, String message) {
if (BuildConfig.DEBUG) {
Log.d(TAG, message);
}
}

public static void logError(String TAG, String message) {
if (BuildConfig.DEBUG) {
Log.e(TAG, message);
}
}

public static void logException(String TAG, Exception exe) {
if (BuildConfig.DEBUG) {
Log.e(TAG, exe.getMessage());
exe.printStackTrace();
}
}
}

After our class is ready we have to call,  

SimpleLog.log(“AppName”,”This is simple way to display logs”); 

 instead of  

SimpleLog.logError(“AppName”,”Error”);  

and that’s how we simplified a way to write logs. ๐Ÿ™‚ 

Note:  

BuildConfig.DEBUG=true  

when apps build variant will be debugged.  

BuildConfig.DEBUG=false  

when apps build variant will be released, so no logs will be displayed. ๐Ÿ™‚

Do you have any product idea or business need?

Unit Testing using Mockk.io

Unit Testing using mockK.io in Kotlin

Learn about unit testing using mockk.io in Kotlin.

Apples In-App Purchase

Hands-On Implementation of Appleโ€™s In-App Purchases On Ruby Based Server

Information about Languages & Tools, Server Configuration and Endpoint & API Setup and many more.

Multi User Chat

Features of Multi User Chat (Group Chat) in Android

Features allows users to visible multiple chatrooms on one or more screens.