Log Messages to Logcat

Kotlin and Android Development featuring Jetpack — by Michael Fazio (118 / 125)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Display Messages with the Toast Class | TOC | Wrapping Up 👉

Logcat is a command-line tool that comes with the Android SDK and takes in system messages, both from the device and apps running on the device. You can use Logcat to see what’s going on in your app without disrupting the UI or having to debug. As Logcat is a command-line tool, a bunch of options are available, which you can find at https://link.mfazio.dev/logcat.

For now, we’re going to focus on using Logcat within Android Studio. The Logcat window can be found on the bottom of Android Studio, near the Run window button:

images/pd.troubleshooting/logcat-window.png

In here, we get information about all kinds of things about our device, no matter if it’s a real device or an emulator. We also have the ability to filter for a specific app, only display messages at a certain log level (which correlates to the importance of the message), and search though log messages for certain phrases or regex patterns. Here, we’re going to print to Logcat when the Play button is hit, then search for our given TAG.

The TAG variable is a common convention within Android apps for giving your log messages a category. This can be any string value you want, but normally we use…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.