当我为我的android应用程序编写日志包装器时,我注意到了androids Log.isLoggable方法的奇怪行为。执行以下代码:
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));
产生以下LogCat输出:
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
为什么我使用冗长和调试日志记录生成这些输出,但我却变得冗长而调试未激活?
最佳答案
无论当前日志级别是什么,所有日志级别都会写入logcat。 isLogabble()
方法可以用作应用程序的优化,以防止将不需要的日志语句发送到logcat。您也可以使用adb logcat
命令过滤日志记录级别的子集,即使将日志记录设置为详细(请参阅https://developer.android.com/studio/debug/am-logcat.html)。