Does logging slow down a production Android app?
Before releasing my开发者_运维知识库 Android app to the marketplace, should I comment out all logs?
Log.d(tag, "example of a log")
If I leave them there, will the app run slower?
Java doesn't support C#-style conditional compilation, so the parameters will always be evaluated. That includes any string concatenation and stuff you might be doing.
Short answer: yes.
You can use:
AppLog.Log(TAG, "example of a log");
Instead:
Log.d(tag, "example of a log")
And this is AppLog
class:
public class AppLog {
public static void Log(String tag, String message) {
if ((BuildConfig.DEBUG)) {
Log.d(tag, message + "");
}
}}
In this case Log
not show when app in release
mode.
Hope this could help you.
Printing a lot of logs does slow down the app. Its a good habit to disable logging for production.
Addition : Refer this for better logging with a logging switch : How do I enable/disable log levels in Android?
精彩评论