KIO
Kreative Ideen online
Log messages

Log messages

Adding messages to alog can be a useful way of checking that your code works the way you want.Youe tell Android what to log in your Java code, and when the app’s running, you check the output in android’s log(a.k.a. logcat).

Yout log messages using one of the followeing methods in the Android.util.Log class

Log.v(String tag, String message)Logs a verbose message.
Log.d(String tag, String message)Logs a debug message.
Log.i(String tag, String message)Logs an information message.
Log.w(String tag, String messageLogs a warning message.
Log.e(String tag, String message)Logs and error message.

There’s also a Log.wtf() method you can use to report exceptions that shoul never happen. According to the Android dcumentation, wtf means “What a Terrible Failure”

Each message is composed of a String tag you use to identify the source of the messae, and the message itself.As an example, to log a verbose message thats’s come from DelayedMessageService, you use the Log.v() method like this:

Log.v("MyService", "This is a message");

You can view the logcat in Android Strudio and filter by the different types of message.To see the logcat, select the Android Monitor option at the bottom of your project screen in Android Sturio and then slect the logcat tab.

Leave a Reply

Your email address will not be published. Required fields are marked *