When I was writing a log wrapper for my android application I noticed a strange behavior of androids Log.isLoggable method. Executing following code:
final String TAG = "Test";
Log.v(TAG, "verbose is active: " + Log.isLoggable(TAG, Log.VERBOSE));
Log.d(TAG, "debug is active: " + Log.isLoggable(TAG, Log.DEBUG));
Log.i(TAG, "info is active: " + Log.isLoggable(TAG, Log.INFO));
Log.w(TAG, "warn is active: " + Log.isLoggable(TAG, Log.WARN));
Log.e(TAG, "error is active: " + Log.isLoggable(TAG, Log.ERROR));
produces following LogCat output:
VERBOSE/Test(598): verbose is active: false
DEBUG/Test(598): debug is active: false
INFO/Test(598): info is active: true
WARN/Test(598): warn is active: true
ERROR/Test(598): error is active: true
Why do I get verbose and debug is not active although I produce these outputs using verbose and debug logging?
All log levels are written to logcat regardless of what the current log level is. The
isLogabble()method can be used as an optimization for your apps to prevent sending unneeded log statements to logcat. You can also use theadb logcatcommand to filter a subset of the logging levels even if the logging is set to verbose (see https://developer.android.com/studio/debug/am-logcat.html).