2

The android app publishing checklist says that I need to delete all Log statements from my code. Does that mean I need to delete them or would just commenting them out do? I would need those Log statements for updation and maintenance purpose later on so i don't want to delete them.Publishing checklist

2 Answers2

3

You don't have to remove your logs from code, just disable them in RELEASE mode. The easiest way to achieve that, check mode before log something

 if (BuildConfig.DEBUG) {
    Log.i("TAG", "Log");
 }

But it will be painful if you have a lot of logs in your code, so good idea is to write your custom wrapper above the Android Log class, with ability to turn on/off logging in one place, for example in Application class.

Or you can use some smart loggers like Timber

EDIT

About log wrapper, to be honest I've never created such wrapper, I prefer to use Timber, but the simplest version may look like this

public class Logger {

    public static void e(String tag, String body) {
        if (BuildConfig.DEBUG) {
            Log.e(tag, body);
        }
    }

    public static void v(String tag, String body) {
        if (BuildConfig.DEBUG) {
            Log.v(tag, body);
        }

    }

    ...
}

and instead of using

Log.e("Tag", "Body");

use

Logger.e("Tag", "Body");
Vasyl Glodan
  • 556
  • 1
  • 6
  • 22
  • can you elaborate on the custom wrapper solution please.? –  Oct 11 '15 at 13:12
  • I commented my Log statements because rewriting them using a custom wrapper would have been a pain. –  Oct 11 '15 at 13:33
  • @user2197909 if having logs in your code is not critical you can of course remove them, but I will be much convenient to use wrapper in the future, because you will always have logs when debug your app. – Vasyl Glodan Oct 11 '15 at 13:36
0

The publishing check list just don't want you to include log statements when your app is published because it may contain some sensitive information and that sort of stuff. So you just need to make sure that it is not executed.

As long as the log statement is not executed, it's fine.

You can do the following:

  • Delete the statement

  • comment the statement

  • add an impossible if statement:

    if (0 != 0) {
       //log
    }

P.S. The second solution the the most recommended.

Sweeper
  • 213,210
  • 22
  • 193
  • 313