本文介绍了如何在 Android 中启用/禁用日志级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我有很多日志语句要调试.
I am having lots of logging statements to debug for example.
Log.v(TAG, "Message here");
Log.w(TAG, " WARNING HERE");
在设备手机上部署此应用程序时,我想关闭详细日志记录,以便启用/禁用日志记录.
while deploying this application on device phone i want to turn off the verbose logging from where i can enable/disable logging.
推荐答案
一个常用的方法是创建一个名为 loglevel 的 int,并根据 loglevel 定义它的调试级别.
A common way is to make an int named loglevel, and define its debug level based on loglevel.
public static int LOGLEVEL = 2;
public static boolean ERROR = LOGLEVEL > 0;
public static boolean WARN = LOGLEVEL > 1;
...
public static boolean VERBOSE = LOGLEVEL > 4;
if (VERBOSE) Log.v(TAG, "Message here"); // Won't be shown
if (WARN) Log.w(TAG, "WARNING HERE"); // Still goes through
稍后,您可以更改所有调试输出级别的 LOGLEVEL.
Later, you can just change the LOGLEVEL for all debug output level.
这篇关于如何在 Android 中启用/禁用日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!