Using Log.d() or Log.e() in my code

Leaving logging statements can, in some cases, be very bad: http://web.archive.org/web/20121222023201/http://vbsteven.com/archives/535

You can use ProGuard to automatically remove them all:

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** e(...);
}

Not only can the user (or any app with log access) see your logs, but your logs also cause your app to run slower and use more battery power.

Writing a log, especially from Java, is probably much more expensive than you think: just building the string in Java is a lot of work.


Consider using this : isLoggable()

Checks to see whether or not a log for the specified tag is loggable at the specified level. The default level of any tag is set to INFO. This means that any level above and including INFO will be logged. Before you make any calls to a logging method you should check to see if your tag should be logged. You can change the default level by setting a system property: setprop log.tag.<YOUR_LOG_TAG> <LEVEL> Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will turn off all logging for your tag. You can also create a local.prop file that with the following in it: log.tag.<YOUR_LOG_TAG>=<LEVEL> and place that in /data/local.prop

Personally for releases, I'd remove the debug logs and keep the error logs using Proguard.


It is better to wrap it like so:

public class MyLog {

public static void d(String tag, String msg) {
   if (Log.isLoggable(tag, Log.DEBUG)) {
       Log.d(tag, msg);
}
}

public static void i(String tag, String msg) {
    if (Log.isLoggable(tag, Log.INFO)) {
     Log.i(tag, msg);
}
}  // and so on... 

You can set logging level by issuing an adb command

Tags:

Android