- #PRINT TO LOG ANDROID STUDIO HOW TO#
- #PRINT TO LOG ANDROID STUDIO ANDROID#
- #PRINT TO LOG ANDROID STUDIO CODE#
#PRINT TO LOG ANDROID STUDIO ANDROID#
In the same pane near the bottom of the window, select Android Monitor from the lower options bar.
#PRINT TO LOG ANDROID STUDIO HOW TO#
In previous lessons you learned how to access the Terminal in Android Studio. Accessing the Logcatįirst, let's locate the logcat in Android Studio, so we'll know where to look for our logged messages.
We'll add several Log messages to our MyRestaurants application together.
Let's walk through the process of logging and viewing data in Android Studio. Similarly, if we were to filter by Log.v(), we would see all other other Log method messages, since Log.v() is the lowest importance level, and each of the other methods is of a higher importance. So, if you filter to view Log.i() messages, you'll see both messages recorded with the Log.i() method and those recorded with the Log.w() and Log.e() methods, because they are of the same importance level or higher.Īdditionally, if we filtered by Log.d(), we would see any messages printed on the logcat from Log.d(), Log.i(), Log.w(), and Log.e() because they are all of Log.d()'s level of importance or higher. ( Log.wtf() is actually a bit of an outlier, and isn’t used very often.) Log.e() is considered to be the highest importance and priority, because it logs information about errors that are currently occurring, and Log.v() is considered the lowest importance and priority because it's meant for logging as much data as possible. The list of Log methods above is ordered by level of importance, also known as "log level". By classifying the importance of the information you're logging using the methods depicted above, we can easily filter messages by their level of importance. Benefits of Different Log Message Typesīut why are there 6 different methods to log information anyway? Well, the logcat can contain a lot of data. It's not used as commonly as the other Log messages. It's meant to record particularly awful issues that should never, ever happen, but are somehow occurring anyway. The wtf in Log.wtf() is said to stand for "What a terrible failure". Use this when you're implementing many, many different log statements as a debugging approach. You'll probably use this one most frequently out of all available Log methods. As you might imagine, you'll use this one for debugging purposes. For instance, maybe you want to double-check a method is being called successfully, you could print an informational message to the log reading something like "X method called!". Developers usually use this to proactively investigate unusual or unexpected behavior in an application. Use this when you suspect an issue may be occurring, but haven't yet received full-on error messages. The Log.e() message can then print details about the error.
#PRINT TO LOG ANDROID STUDIO CODE#
Developers will commonly use this in a block of code meant to catch an error. Use this when you know an error has occurred, and you're logging details about that error. Let's briefly cover what these different methods are, and when to use each: Log.e() However, unlike JavaScript's console.log(), there are many different methods from Android's Log class we can use to log information. It both displays messages in real time and also keeps a history so you may view older messages.Īfter placing Log methods we can run our app and look view the logcat to see what data or information has been recorded. The logcat displays system messages, and messages/information you manually record with Log methods.
We can add log methods that will write data to Android Studio's logcat. This allows us to see what certain variables are defined as, or check whether methods are being called.Īndroid Studio has the capability to write log messages in a very similar manner. It’s a method that allows us to write to the JavaScript console in the browser. When writing JavaScript in your Intro to Programming and JavaScript courses, you probably encountered console.log(). Then, in the next lesson we'll learn how to add breakpoints to strategically pause our code and narrow down where bugs and errors are occurring. First, we'll learn how to record helpful information into an area of Android Studio known as the logcat.
In the next two lessons we'll explore two Android-specific approaches to debugging. Bugs occur all the time, and that's simply a normal part of development. Sometimes code that once worked perfectly no longer functions after implementing new code. Sometimes code doesn't work on the first try. Now that you're in your level 3 Epicodus course, you've probably come to realize how much trial-and-error goes into coding.