Easy logging switch between debug/release version without modifying source code. Logging code will be completely removed by the compiler in release build so that they have no impact on code size and run-time performance.
Debug version of Config.java:
package com.test;
public class Config {
public static final boolean D = true;
public static final boolean V = true;
}
Release version of Config.java:
package com.test;
public class Config {
public static final boolean D = false;
public static final boolean V = false;
}
The build script can select one of them to build debug or release version.
In a class that wants to use the switch:
import static com.test.Config.D;
...
if (D) Log.d(TAG, ...);
4 Comments
But who wants to not have logs?
I think that's quite useful! Especially since logging slows down the apps a bit (depending on how often you log stuff), and turning that off for the release version is recommended by google.
Look at this http://developer.android.com/reference/android/util/Log.html If you use Log.isLoggable(...), than you do not need to bother with performance. You just set the system property during debugging. This property will not be set in user's handsets so it does not slow down application in production.
And that works for you? That's weird, in my debug builds, RELEASE is true and DEBUG is false.