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

前端之家收集整理的这篇文章主要介绍了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

原文链接:https://www.f2er.com/android/316641.html

猜你在找的Android相关文章