Does Log.isLoggable returns wrong values?(Log.isLoggable 是否返回错误值?)
问题描述
当我为我的 android 应用程序编写日志包装器时,我注意到 androids Log.isLoggable 方法的一个奇怪行为.执行以下代码:
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));
产生以下 LogCat 输出:
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?
推荐答案
无论当前的日志级别是什么,所有的日志级别都会写入 logcat.isLogabble()
方法可用作您的应用程序的优化,以防止向 logcat 发送不需要的日志语句.您还可以使用 adb logcat
命令过滤日志记录级别的子集,即使日志记录设置为详细(请参阅 https://developer.android.com/studio/debug/am-logcat.html).
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 the adb logcat
command 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).
这篇关于Log.isLoggable 是否返回错误值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Log.isLoggable 是否返回错误值?


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01