过多的日志写入会降低android应用程序性能吗? [英] Does too many log writing decreases android application performance?

查看:629
本文介绍了过多的日志写入会降低android应用程序性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道日志记录是否会降低应用程序性能? 另外,请给我一些技巧来提高android应用程序的性能.

I would to know whether logging can decrease application performance? Also, please give me some tips to increase android application performance.

推荐答案

是.过多的日志记录会影响任何应用程序的性能,而不仅仅是Android.

Yes. Excessive logging affects the performance of any application not just Android.

开发人员指南建议您在发布之前停用和禁用日志记录:

The developer guide suggests you to deactivate and disabled logging before release:

关闭日志记录和调试功能确保停用日志记录并调试 在构建应用程序之前,请禁用调试选项 释放.您可以通过删除对Log方法的调用来停用日志记录 在您的源文件中.您可以通过删除调试来禁用调试 您标签中的android:debuggable属性 清单文件,或将android:debuggable属性设置为false 在清单文件中.另外,删除所有日志文件或静态测试文件 在您的项目中创建的.

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.

此外,您还应该删除添加到自己的所有Debug跟踪调用 代码,例如startMethodTracing()和stopMethodTracing()方法 电话.

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

因此,您应禁止在应用的发行"或生产"版本中删除日志.

So, you should suppress the logs in "release" or "production" build of your App.

通过设置可调试在Android Manifest中将其关闭:

<application android:icon="@drawable/icon" 
        android:label="@string/app_name"
        android:debuggable="false">


另一种方式

创建您自己的记录器类,并在执行日志之前检查调试模式.它允许在调试模式和已部署的应用程序之间进行单点修改,并允许执行其他操作,例如写入日志文件.

Create your own logger class and check for debugging mode before executing log. It allows single point modification between debugging mode and deployed application and allows extra things to do such as writing to log file.

import android.util.Log;
public class MyLog {
    private static final boolean isDebug = false;;
    public static void i(String tag, String msg) {
        if (isDebug) {
            Log.i(tag, msg);
        }
    }
    public static void e(String tag, String msg) {
        if (isDebug) {
            Log.e(tag, msg);
        }
    }
}


有关更多信息,请阅读 http://rxwen.blogspot.com/2009/11/logging-in-android.html


For further info read http://rxwen.blogspot.com/2009/11/logging-in-android.html

和SO质量保证:

Log.d及其对性能的影响

Android日志记录-如何清除以获得更好的性能

这篇关于过多的日志写入会降低android应用程序性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆