微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐