9

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?

JoJo
  • 19,587
  • 34
  • 106
  • 162
  • 1
    You should look at this one : http://stackoverflow.com/questions/2018263/android-logging/2019563#2019563 – Matthieu Jun 22 '11 at 19:10

3 Answers3

12

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.

Blindy
  • 65,249
  • 10
  • 91
  • 131
  • 1
    Can you give a quantitative measure of the delay if possible? – Sreekanth Karumanaghat Jun 22 '17 at 12:07
  • At least a couple of function calls' worth, more if you do complex operations to figure out what you're sending (flattering arrays into strings, tight loop logs, tight loops in logs, etc). It really depends, I'd have to see your code! – Blindy Jun 26 '17 at 14:53
7

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.

Iman Marashi
  • 5,593
  • 38
  • 51
1

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?

Community
  • 1
  • 1
Ravi Vyas
  • 12,212
  • 6
  • 31
  • 47