Use the built-in logger
Copy paste from the documentation: Usually use
- Log.v ()
- Log.d ()
- Log.i ()
- Log.w ()
- Log.e ()
methods.
The order from the point of view of verbosity, from smallest to largest, is ERROR, WAR, INFO, DEBUG, VERBIS. Details should never be compiled into an application, except during development. Debug logs are compiled but deleted at runtime. Error, warning and information logs are always kept.
Tip. A good convention is to declare a TAG constant in your class:
private static final String TAG = "MyActivity";
and use this in subsequent calls to the log methods.
Tip. Do not forget that when you make a call, for example
Log.v(TAG, "index=" + i);
that when you create a string to pass to Log.d, the compiler uses StringBuilder and there are at least three distributions: the StringBuilder itself, the buffer, and the String object. Actually, there is another distribution and copying of the buffer, and even more pressure on gc. This means that if your log message is filtered, you may be doing a lot of work and you will get significant overhead.
Frank source share