Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does too many log writing decreases android application performance?

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

like image 281
Vishnu Rajan Avatar asked Oct 21 '11 04:10

Vishnu Rajan


Video Answer


2 Answers

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

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

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.

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

Turn off it in Android Manifest by setting debuggable:

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

Another way

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);
        }
    }
}


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

and The SO QAs :

Log.d and impact on performance

Android Logging - How to clear for better performance

like image 154
gtiwari333 Avatar answered Oct 13 '22 03:10

gtiwari333


use 'if' statement before log writing.
you can disable log when application release.

example :

public class LogTest extends Activity {

private static final String TAG = "YOUR_LOG_TAG_NAME";
private static final boolean mDebug = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //--[Start Log example]-----------------------------------------
    if(mDebug) Log.d(TAG, "Log Write Test");
    //--[End Log example]-----------------------------------------
}

}

like image 44
IvoryCirrus Avatar answered Oct 13 '22 03:10

IvoryCirrus