如何启用/ Android中禁用日志级别? [英] How do I enable/disable log levels in Android?

查看:185
本文介绍了如何启用/ 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.

推荐答案

一个常见的​​方式是让一个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.

这篇关于如何启用/ Android中禁用日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆