Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are Android's debug logs really stripped at runtime?

Android documentation ( http://developer.android.com/reference/android/util/Log.html ) says:

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

I just did a test. In my activity I wrote:

private static String test(String what) {
    Log.e("test", "I am called with argument: " + what);
    return what;
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.v("test", "log level: " + test("v"));
    Log.d("test", "log level: " + test("d"));
    Log.i("test", "log level: " + test("i"));
    Log.w("test", "log level: " + test("w"));
    Log.e("test", "log level: " + test("e"));
}

I exported my project as an apk file, then I installed this apk on my phone. I run this application on my phone, then I looked at logs. There I saw that the function test was called all five times and all five calls to Log.something functions resulted in its text being written to logs.

So are Log.d calls really stripped at runtime?

like image 482
user983447 Avatar asked Mar 06 '13 03:03

user983447


People also ask

Is logging time consuming?

Logging Is a Manual Time-Consuming Process Also, the process is error-prone. Developers might be spending a lot of time adding logs but will still miss the exact information they need in production.

Why is it important to remove all debug log statements before releasing an app for general distribution and use?

Logs can lead to unauthorized access to your application or/and server. Such access can lead to very serious security problems (for example user data leaks).

Does logging affect performance?

Logs Can Have a Strong Impact on Stability, Performance, and Garbage Collection.


1 Answers

No. You have to do this yourself. You can make your own Log.d wrapper like this:

public static void debug(String tag, String msg) {
    if (BuildConfig.DEBUG) {
        Log.d(tag, msg);
    }
}
like image 175
Shellum Avatar answered Oct 21 '22 08:10

Shellum