如何启用/ Android中禁用日志级别?级别、日志、Android

2023-09-11 11:07:08 作者:星星坠入你的眼睛

我有很多的日志记录语句到调试的例子。

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.

推荐答案

一个常见的​​方式是让一个int名为日志级别,其调试级别基于日志级别定义。

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.