android – 在我的代码中使用Log.d()或Log.e()

我已经使用Log.d()和Log.e()通过我的 android应用程序进行调试.
我想知道如果我发布这样的应用程序,用户是否会看到我放入的所有调试语句?我是否需要做一些特别的事情,以便即使用户连接’adb logcat’,用户也看不到调试日志?

谢谢.

解决方法

考虑使用它: isLoggable()

Checks to see whether or not a log for the specified tag is loggable at the specified level. The default level of any tag is set to INFO. This means that any level above and including INFO will be logged. Before you make any calls to a logging method you should check to see if your tag should be logged. You can change the default level by setting a system property: setprop log.tag.<YOUR_LOG_TAG> <LEVEL> Where level is either VERBOSE,DEBUG,INFO,WARN,ERROR,ASSERT,or SUPPRESS. SUPPRESS will turn off all logging for your tag. You can also create a local.prop file that with the following in it: log.tag.<YOUR_LOG_TAG>=<LEVEL> and place that in /data/local.prop

就个人而言,我会删除调试日志并使用Proguard保留错误日志.

最好像这样包装它:

public class MyLog {

public static void d(String tag,String msg) {
   if (Log.isLoggable(tag,Log.DEBUG)) {
       Log.d(tag,msg);
}
}

public static void i(String tag,String msg) {
    if (Log.isLoggable(tag,Log.INFO)) {
     Log.i(tag,msg);
}
}  // and so on...

您可以设置日志级别by issuing an adb command

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...