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:
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();
ERROR
: Log.e()
Exception
.WARN
: Log.w()
INFO
: Log.i()
DEBUG
: Log.d()
VERBOSE
: Log.v()
ASSERT
: Log.wtf()
E/MyApplication: Process: com.example.myapplication, PID: 25788
com.example.SomeRandomException: Expected string, got 'null' instead
Followed by a bunch of stack traces that would eventually lead to the offending line, where stepping through with a debugger would eventually lead to the problem
However, the log trace of an application with logging enabled could look something like this:
V/MyApplication: Looking for file myFile.txt on the SD card
D/MyApplication: Found file myFile.txt at path <path>
V/MyApplication: Opening file myFile.txt
D/MyApplication: Finished reading myFile.txt, found 0 lines
V/MyApplication: Closing file myFile.txt
...
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.
For more documentation and examples visit Logging and using Logcat