开发者

Does logging slow down a production Android app?

开发者 https://www.devze.com 2023-03-14 22:27 出处:网络
Before releasing my开发者_运维知识库 Android app to the marketplace, should I comment out all logs?

Before releasing my开发者_运维知识库 Android app to the marketplace, should I comment out all logs?

Log.d(tag, "example of a log")

If I leave them there, will the app run slower?


Java doesn't support C#-style conditional compilation, so the parameters will always be evaluated. That includes any string concatenation and stuff you might be doing.

Short answer: yes.


You can use:

AppLog.Log(TAG, "example of a log");

Instead:

Log.d(tag, "example of a log")

And this is AppLog class:

public class AppLog {

public static void Log(String tag, String message) {
    if ((BuildConfig.DEBUG)) {

        Log.d(tag, message + "");
    }
}}

In this case Log not show when app in release mode.

Hope this could help you.


Printing a lot of logs does slow down the app. Its a good habit to disable logging for production.

Addition : Refer this for better logging with a logging switch : How do I enable/disable log levels in Android?

0

精彩评论

暂无评论...
验证码 换一张
取 消