Update: reorganized question and title:
I always thought that expensive Android logging methods could be optimized by asking if logging is active in this way.
import android.util.Log; if (Log.isLoggable("MyContext", Log.DEBUG)) { Log.d("MyContext", "my logging: " + callExpensiveCalculation()); }
However, when I try to use this with the Android 2.2 emulator, my Log.d () is never called.
So I tried this code
Log.v(MY_CONTEXT, "VERBOSE logging is active: " + Log.isLoggable(MY_CONTEXT, Log.VERBOSE)); Log.d(MY_CONTEXT, "DEBUG logging is active: " + Log.isLoggable(MY_CONTEXT, Log.DEBUG)); Log.i(MY_CONTEXT, "INFO logging is active: " + Log.isLoggable(MY_CONTEXT, Log.INFO)); Log.w(MY_CONTEXT, "WARN logging is active: " + Log.isLoggable(MY_CONTEXT, Log.WARN)); Log.e(MY_CONTEXT, "ERROR logging is active: " + Log.isLoggable(MY_CONTEXT, Log.ERROR));
and to my surprise I got
02-27 19:05:43.015: V/MyContext(334): VERBOSE logging is active: false 02-27 19:05:43.015: D/MyContext(334): DEBUG logging is active: false 02-27 19:05:43.015: I/MyContext(334): INFO logging is active: true 02-27 19:05:43.015: W/MyContext(334): WARN logging is active: true 02-27 19:05:43.015: E/MyContext(334): ERROR logging is active: true
therefore, logging works even if logging is disabled. Is this a bug in android or in my test code?
Is there any other way to find out if debugging is active (or one of the other loglevel levels)?
I am using eclipse logcat-view with detailed logic level and started checking with eclipse using asroid-app
source share