Log.d和对性能的影响 [英] Log.d and impact on performance
问题描述
谢谢,
我有点困惑,因为如果你读到关于日志对象(文档)你看到这样:
详细信息,从最少到大部分是ERROR,WARN,
INFO,DEBUG,VERBOSE。除非在开发过程中,否则不应将编译成
应用程序的调试日志被编译为
在运行时被剥离错误,警告和信息日志总是保留。
几乎听起来像把剥离了。无论如何,感谢您的答案,当我完成后,我会评论他们。
谢谢
日志对性能有影响,因此建议您将其注释或使用条件语句进行日志记录。
例如
public class MyActivity extends Activity {
//调试
private static final String TAG =MyApp;
private static final boolean D = true;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if(D)Log.e(TAG,MyActivity.onCreate debug message);
}
然后在发布发布版本时,将D更改为false
I'm not entirely sure about what I'm reading in the documentation. Is it ok to leave a bunch of log.d pieces of code scattered about, or should I comment them out so that they don't impact my app's performance.
Thanks,
I'm a little confused because if you read about the log object (documentation) you see this:
"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. "
It almost sounded like it's ok to leave debug messages in there because they are "stripped." Anyway, thanks for the answers, I'll comment them out when I'm done. Not like I need them in there once the app is completed.
Thanks
Log has impact on performance, so it's recommended that you comment it out or log with conditional statements.
For example
public class MyActivity extends Activity {
// Debugging
private static final String TAG = "MyApp";
private static final boolean D = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(D) Log.e(TAG, "MyActivity.onCreate debug message");
}
Then in when you publish your release version just change "D" to false
这篇关于Log.d和对性能的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!