-2

I am in a strange issue in a project I am working on.

My Issues :

  • I have lots of Log.e, Log.i, Log.d
  • I need to remove it in release build
  • I am not willing to remove all logs manually because its a big headache

Why I am positing this question :

  • Is it possible to remove all logs in release version of apk without using Proguard { Because using proguard is irritating with lots of rules and regulations and personally I don't like it ;-) }

  • Any 3 rd PARTY library is there to achieve this

  • I tried using TIMBER but I think its not so easy to achieve

Note : Some persons has downvoted the question. I have an suggestion to them If I am asking anything bad or wrong its better to downvote. I am asking for alternate solutions. Kindly don't discourage us.

Raghul Sugathan
  • 350
  • 1
  • 7
  • 22
  • 1
    You don't have to use and configure everything proguard has to offer. Log removal with it is quite simple and straightforward. – laalto Nov 10 '17 at 06:50
  • 1
    Possible duplicate of [Remove all debug logging calls before publishing: are there tools to do this?](https://stackoverflow.com/questions/2446248/remove-all-debug-logging-calls-before-publishing-are-there-tools-to-do-this) – ישו אוהב אותך Nov 10 '17 at 07:00
  • @laalto Thanks for your comment. I am aware that of it. I need to know is there any other methods available other than proguard. It will be useful to me in many manner. – Raghul Sugathan Nov 10 '17 at 07:10
  • Just write a simple utils class that wraps `Log` and checks `BuildConfig.DEBUG`. You still get stuck with the stub method calls, but you say specifically that you don't want to use the tool designed to remove those calls. – Richard Le Mesurier Nov 10 '17 at 07:17
  • @RichardLeMesurier I just saw your comment after posting my answer. Let me know if you want me to delete my answer – AesSedai101 Nov 10 '17 at 07:29
  • @ישואוהבאותך This question is not a duplicate of what you have mentioned. I went through that question initially and many solutions mentioned in that question is based on proguard. So I need a answer without proguard. Hope you got it. – Raghul Sugathan Nov 10 '17 at 07:32
  • 1
    @AesSedai101 No Need to delete. Thanks for your time and effort. – Raghul Sugathan Nov 10 '17 at 07:32
  • 1
    What's the problem with using Timber? If you having a problem for changing all the log to Timber, you can see https://github.com/JakeWharton/timber/issues/119 – ישו אוהב אותך Nov 10 '17 at 07:45
  • This is helpful to me. I am not aware of migrating like this from TIMBER. I am using other ways of migration. @ישואוהבאותך – Raghul Sugathan Nov 10 '17 at 07:59
  • @AesSedai101 No need to delete. Glad someone took the time I didn't have. Happily upvoted your answer. – Richard Le Mesurier Nov 10 '17 at 10:09

2 Answers2

1

If you are really insistent on not using Proguard, you can build a "wrapper" around the built-in Log framework. Instead of calling the Android Log statement, you would then call your wrapper. For example:

public class LogWrapper {
    public static void d(String tag, String message) {
        if (BuildConfig.DEBUG) {
            Log.d(tag, message);
        }
    }
}

However, I strongly recommend using proguard, since this approach is error-prone and requires that you remember to invoke your LogWrapper every time you need to log something

AesSedai101
  • 1,502
  • 2
  • 23
  • 37
  • 1
    One enhancement to this that I suggest is to use object varargs instead of `String message`, avoiding expensive string creation code outside the log method. [You can see this technique in my `Dbug` gist](https://gist.github.com/mobiRic/9786897) (which works very well with proguard too, but is a bit out of date). – Richard Le Mesurier Nov 10 '17 at 11:38
0

You can use progruard rules to eliminate calls to Log in release version, see this answer https://stackoverflow.com/a/2466662/4428159

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}
Umar Hussain
  • 3,461
  • 1
  • 16
  • 38