其他分享
首页 > 其他分享> > 为什么不应该在设备上显示Log.d()消息?

为什么不应该在设备上显示Log.d()消息?

作者:互联网

Android文档指出:

The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.

但是尝试执行Log.d(),您会发现它实际上仍在实际设备上记录到Logcat.

有人知道为什么吗?还是如何禁用它?

谢谢!

解决方法:

您所看到的是预期的行为.如果使用logcat并连接设备,则Log.d将始终被记录并可见.因此,如果您不希望在生产应用程序中调试日志,请将其关闭.实际上,Android SDK建议您这样做.这样的答案可能也对您有帮助. Should I comment my log calls when creating my final package?

安德里奥·SDK说

Turn off logging and debugging

Make sure you deactivate logging and disable the debugging option
before you build your application for release. You can deactivate
logging by removing calls to Log methods in your source files. You can
disable debugging by removing the android:debuggable attribute from
the tag in your manifest file, or by setting the
android:debuggable attribute to false in your manifest file. Also,
remove any log files or static test files that were created in your
project.

Also, you should remove all Debug tracing calls that you added to your
code, such as startMethodTracing() and stopMethodTracing() method
calls.

Source

标签:logcat,android-logcat,android
来源: https://codeday.me/bug/20191101/1983996.html