I use Log functions to debug my Android app. I'm close to releasing my app and I'd like to reduce debug level. However I don't know how to disable some of these function. Say I just want to disable Log.v() logs.
Android doc says here that one should remove Log functions calls in code or remove/set to false the android::debbugable option. The first option does not fit my needs, since I'd like to Log calls in my source code (for future updates). The second option disables all logs, which is not convenient for pre-release testing.
Do you know how to disable only verbose (Log.v) logs ?
Many thanks!
You could create your own wrapper for the Log
-class, maybe something like this:
static class MyLog{
private static int mLevel;
public final static void setLevel(int level){
mLevel = level;
}
public final static void v(String tag, String message){
if( mLevel > 0 ) return;
Log.v(tag, message);
}
public final static void d(String tag, String message){
if( mLevel > 1 ) return;
Log.d(tag, message);
}
public final static void i(String tag, String message){
if( mLevel > 2 ) return;
Log.d(tag, message);
}
//Same for w and e if neccessary..
}
Then you can use MyLog.setLevel(1);
to disable any verbose logging (or a higher level to disable those logs as well).
If you are going to obfuscate your release with Proguard, then putting lines such as
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
into the config file will remove those categories of logging from your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With