Verbose logging on Android

Go To StackoverFlow.com

2

If you lookup the logging documentation on Android Dev you there is a section which reads

The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.

The second part of this blurb is what is currently confusing me. Does that mean that

a) The compilers optimizer automatically strips out all verbose logging (like it is suggested specifically doesn't in debug)

or

b) That I should before release find and replace all Log.v() with ""

I realise that verbose logging is not desirable to end users, which I completely agree with, but I also believe during development logs should be utilized as much as possible. I realise I could in theory do something along the lines of

if(IS_VERBOOSE_LOGGING_ENABLED) 
{ 
    Log.v("My log message here");
} 

However this still would violate the suggestion (assuming that it mean to strip out before compile time).

Any clarifications form the community would be greatly appreciated.

2012-04-05 01:04
by John Mitchell
There is a great discussion on that, see http://stackoverflow.com/questions/2446248/remove-all-debug-logging-calls-before-publishing-are-there-tools-to-do-this?lq=1 Apparently those calls are never stripped out by default on release version. You always have to check log level before logging as u suggested. Log.isLoggable(Log.VERBOSE) might be a replacement for your ISVerboseloggingenabled. http://developer.android.com/reference/android/util/Log.html#isLoggable%28java.lang.String,%20int%2 - OneWorld 2013-06-20 21:32


2

The best thing to do it to just configure proguard to get rid of all the logging in your release artifact. Then you don't need to worry at all.

# get rid of all the logging
-assumenosideeffects class android.util.Log {
    public static int v(...);
    public static int d(...);
    public static int w(...);
    public static int i(...);
}
2012-04-05 01:07
by Manfred Moser
But please note then your line numbers in stack traces won't match - lzap 2012-04-24 07:42
@lzap well, if you're using ProGuard, the line numbers in stack traces don't match regardless of whether this configuration is added or not - Felix 2013-11-15 14:48
And if you preserve the mapping file from the proguard run you can deobfuscate it.. - Manfred Moser 2013-11-15 16:57
Ads