Log.isLoggable 是否返回错误值?

Does Log.isLoggable returns wrong values?(Log.isLoggable 是否返回错误值?)
本文介绍了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 是否返回错误值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)