Does too many log writing decreases android application performance?
Asked Answered
C

3

12

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

Comrade answered 21/10, 2011 at 4:46 Comment(3)
Use log for only debugging...Delete all log messages when you upload the actual build..Radiogram
Excessive logging can have a small impact on performance, but generally not. (see the links in @gt_ebuddy answer). While doing development being connected to DDMS will slow down the app.Wellesz
Possible duplicate of Log.d and impact on performanceRelieve
H
19

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

Hydromechanics answered 21/10, 2011 at 4:53 Comment(2)
In my experience the manifest setting has no impact on log output. It simply controls if a debugger can attach to your application.Wellesz
@cistears Does setting debuggable = "false" help in increasing efficiency?Daffy
C
1

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]-----------------------------------------
}

}

Carmencarmena answered 21/10, 2011 at 4:58 Comment(0)
I
1

Any text output in excess will slow down your application, even with a desktop application. Excessive logging does slow things down, but you would basically need an insane amount of data being sent through, which by the way, isn't that hard to do with a for or while loop. Things that happen in the background while logging sometime include string manipulation, text rendering, cache management, data filtering, log length limiting, and the list goes on.

There's several ways to remove logcat from your final app, especially those involving ProGuard. ProGuard didn't work for me, but there's plenty of brilliant ideas out there on how to remove them including scripting programs like sed.

Inviolable answered 8/8, 2012 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.