Any quality Android application will keep track of what it’s doing through application logs.

These logs allow easy debugging help for the developer to diagnose what’s going on with the application. Full Android Documentation can be found here, but a summary follows:

Basic Logging

The Log class is the main source of writing developer logs, by specifying a tag and a message. The tag is what you can use to filter log messages by to identify which lines come from your particular Activity. Simply call

Log.v(String tag, String msg);

And the Android system will write a message to the logcat:

07-28 12:00:00.759 24812-24839/my.packagename V/MyAnimator: Some log messages
 └ time stamp             |  app.package┘     |    └ any tag  |
     process & thread ids ┘          log level┘               └ the log message

TIP: Notice the process id and the thread id. If they are the same - the log is coming from the main/UI thread!

Any tag can be used, but it is common to use the class name as a tag:

public static final String tag = MyAnimator.class.getSimpleName();

Log Levels

The Android logger has 6 different levels, each of which serve a certain purpose: - ERROR: Log.e() - Used to indicate critical failure, this is the level printed at when throwing an Exception. - WARN: Log.w() - Used to indicate a warning, mainly for recoverable failures - INFO: Log.i() - Used to indicate higher-level information about the state of the application - DEBUG: Log.d() - Used to log information that would be useful to know when debugging the application, but would get in the way when running the application - VERBOSE: Log.v() - Used to log information that reflects the small details about the state of the application - ASSERT: Log.wtf()

- Used to log information about a condition that should never happen.
- *wtf* stands for "What a Terrible Failure".

E/MyApplication: Process: com.example.myapplication, PID: 25788 com.example.SomeRandomException: Expected string, got ‘null’ instead ```

A quick glance at the logs and it is obvious that the file was empty.

Things To Considering When Logging:

Although logging is a powerful tool that allows Android developers to gain a greater insight into the inner working of their application, logging does have some drawbacks.

Log Readability: