Log.isLoggable 是否返回错误值?

时间:2023-04-21
本文介绍了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 是否返回错误值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:“模拟器:警告:打开音频输入失败"AVD 启动时显示在控制台中 下一篇:无法在模拟器上的/storage/emulated/0 上创建目录

相关文章