While there are many tools in Android Studio that play a vital role in developing a high quality and customized mobile applications of your need, if you have experience building one through Android Studio, you realize the importance of Logcat in your development process.
It is a command line window usually in the bottom half of the screen that helps you debug your app by displaying logs from your device in real time, for example, messages that you added to your app with the Log class, messages from services that run on Android, or system messages, such as when a garbage collection occurs.
What is Logcat
Logcat is one of the most important tools for a developer looking to build high-quality apps. This tool is especially useful when working within large codebases where there are hundreds to thousands of lines of code because if you encounter any sort of error in such a codebase, without the help of logcat it will take a lot of time out of you to figure out where the issue actually resides.
Also, when an app throws an exception, Logcat shows a message followed by the associated stack trace containing links to the line of code. This is just one of the ways how it assists developers in this regard as it makes it easier for them to locate errors when running the code.
Logcat Changes in Android Studio
While the newer versions of Android Studio kept coming out at regular intervals, each of them having their own updated but experimental versions of Logcat, the developers were more comfortable in sticking with the older stable version that included a drop-down to choose which type of logs they are interested to see.
From the older version, you could pick verbose, debug, information, warning and error from the drop-down and the Logcat tool would just provide those specific messages relevant to the category you selected. Personally, I really liked that Logcat myself as apart from having the practice to use it a lot, it was very simple and easy to use because I’d get the information I want fairly quickly so it was really convenient for me.
But not so much with the newer version and it’s not only me, the majority of the Android community is not happy with this.
Why Does New Logcat Style Need Improvement?
A lot of developers in the community found the newer version in Android Studio Giraffe 2022.3.1 to be really cluttered and unorganized. Personally, the only thing I really understood when I first saw it were the color tags to distinguish the message categories of debug, error etc.
Sometimes, the information that I’m looking for takes minutes to find and if I encounter an error while working in a fairly large codebase, it’s even worse because there’s too much information that is of no use. The above image of the Android Studio Giraffe logcat is just from executing “Hello World” and there were even more messages that couldn’t fit in the image. If there are that much cluttered messages for just a “Hello World” execution, you can imagine a scenario where you’d have to debug a relatively larger application.
How to Disable Logcat in Android Studio Giraffe
Many developers (including me) used to go back to the older version of Logcat by going to Settings > Experimental and uncheck the “Enable new Logcat tool window” and we would get back to the older version. However, since the release of the new Giraffe Android Studio, the updated Logcat is no longer in the Experimental category and at the time of writing this article, there has been no official way to get to the older version.
But there is a way where you can get pretty close to the original version of Logcat. The above examples of the Giraffe version shows the “Standard View” which is obviously not pleasing to the eye, however, the “Compact View” through “Modify Views” lets you choose which part of information you want from the Standard View.
To select the Compact View of Logcat: Click the Logcat window tab -> Click “Configure Logcat Formatting Options” on the left side. Select Compact View.
If you want to customize the Logcat information, you can also select “Modify Views”. This will allow you to choose which information you desire to be shown to yourself and with its customized line spacing. This will, to the very least, not make the information shown by Logcat in an unorganized manner.
The new Logcat can still be useful if you’re looking to see the errors in your application. The newer version introduced a mechanism in the Logcat through which we can identify any specific category of error, debug, verbose etc. So far, I have been using this functionality to figure out the error messages in my apps. It’s not exactly the same as the old Logcat style where you can use dropdown to see the messages but it’s still useful in its own way.
How to Debug using Logcat in Android Studio
If you’re someone that still doesn’t like to see the errors from Logcat, no worries you can still choose to see them through the ”Problems” tab on the same menu bar where Logcat exists and you can see the descriptive and direct error message that also shows the line number where the error is at. The line number is written after the error message and a semicolon.
The debug functionality of Logcat is still there. You can write log statements with tags and messages to make a checkpoint for your application, ensuring that your code has gone through that checkpoint. This is really useful if you’re looking to see the application flow and is a genuine tool specifically designed for this. The usual syntax for writing log messages is:
Log.i(tag: String?, msg: String)
The tag is the identifier for the checkpoint that you’re looking to make and the message is what you write on that checkpoint. The example shows the log message with the tag “MainActivity” and the adjacent message “We’re at onCreate of MainActivity” and after running, the Logcat shows the checkpoint we created and it means that the code processed this line and has crossed that checkpoint.
I’d still put my fingers crossed and hope that the Android IDE . Android Studio development team is still considering feedback and would look to enhance and make the Logcat experience better for the developers. There is definitely a lot that can be done in improving the developer productivity in this regard apart from the other measures that they have taken in their latest release of Android Studio Giraffe.
The other key measures in this release have so far been excellent but I do believe that there is still a lot more that can be possible. Maybe revert back to what was working? Maybe we can get back our dropdown version of Logcat? Who knows apart from the devs of Android Studio. Comment below your thoughts about this Logcat version and if you liked it, share with us its impressive points and if not, share with us how it can be better.