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?
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.
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).
Logs Can Have a Strong Impact on Stability, Performance, and Garbage Collection.
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With