Affiliate Disclosure: By buying the products we recommend, you help keep the lights on at MakeUseOf. Read more.
Android does a really good job of hiding the nitty-gritty from its users. When things go wrong, you don’t see an intimidating wall of cryptic text, much like you do on a Mac. They just… Go wrong.
While that’s great for most people, it’s less helpful for developers who want to see why their apps aren’t working, and for power users who want to take a more hands-on approach.
Which is why logcat is so incredibly helpful. It allows you to get a dump of your phone or tablet’s system logs in order to debug problems. Although most users won’t have a use for it, developers will sometimes ask users to provide them with their device’s log files when a problem arises. Here’s how you can install logcat, and how to use it.
Before you start producing system logs, you’re first going to need to fulfill some prerequisites. The first is to install the Android Debug Bridge, commonly known as ADB. This contains the Logcat tool.
If you’re on a Mac, like I am, the simplest way to do this is using the HomeBrew package manager. Once installed, you just need to run “brew install android-platform-tools”.
If you’re on Linux, the steps required to install ADB will vary wildly between distributions. If you’re on Ubuntu, you just need to run “sudo apt-get install android-tools-adb”.
Finally, if you’re on Windows, you’ve got a couple of options. First, XDADevelopers has a one-click ADB installer, which includes the drivers needed and FastBoot. Alternatively, you can install it through the Chocolatey package manager, although the version available isn’t the newest.
Put Your Device Into Developer Mode
Next, you’re going to enable developer mode on your device. To do that, open your settings and head to “About Phone” or “About Tablet”. Then, scroll down to the bottom of the screen and tap “Build Number” seven times. Once you’ve done that, it should tell you that you’ve entered Developer Mode.
Press back and go to the Settings root directory, where you should see something that says “Developer Options”. Tap that.
Then, switch USB Debugging on and plug your Android device into your computer. If everything worked alright, you should see a stern-looking warning pop up on your device.
Looking At Logs
Now we can start looking at logs. Open up a new terminal or command prompt, and run “adb logcat”. You should then see system messages cascade down your terminal window. If you don’t, that means something’s gone wrong. Either your device isn’t connected to your computer, ADB wasn’t installed correctly, or you don’t have USB debugging running on your device.
So, what if you want to copy your phone or tablet’s system messages to a text file, for later analysis? Well, the syntax for redirecting output is the same on Windows as it is on a Mac. Just run “adb logcat > textfile.txt”. You can also accomplish this by running “adb logcat -f filename”.
It’s worth pointing out that logcat will run for as long as you tell it to. If you’re copying output to a text file and forget to end the connection, you shouldn’t be surprised if you end up with no hard drive space. To close it, just press CTRL-C.
As anyone who has ever worked in DevOps or systems administration will tell you, log files can quite easily stretch into the tens of gigabytes, and beyond. You’ve been warned.
A Note On Filtering Output
It’s worth noting that you can tell logcat to prioritize certain types of output. If you run logcat with the “V” flag (“adb logcat V”), you’ll see absolutely everything. That’s because you’ve enabled “verbose mode”.
But there are other triggers which show you more specific types of error messages. The “I” trigger only shows you info, while “D” shows debug messages. For more information, check out the official Android Debug Bridge documentation.
Although, it’s worth noting that unless you’ve been told otherwise, it’s best to run logcat using the default settings. This is so that the person who has requested the log file can get all the information they need to fix their app, and they don’t miss anything.
Is There A Solution For Rooted Devices?
Actually, yes! If you’ve got a rooted phone or tablet, you can install “aLogCat” from the Google Play Store. This comes in a free version, and a paid version. Both are identical, although the latter supports the developer financially.
What makes aLogCat different is that it runs directly on your device, and comes with some features that make it easier to deal with error logs.
Messages are highlighted, allowing you to visually see which messages are errors, and what are innocuous system notifications. You can also share them through email, bluetooth, and on PasteBin via PasteDroid.
If you want to continuously save your logs directly to an SD card, you’ll have to download a different application called aLogRec. This too comes in a free version and a donate version, and it can be acquired from the Google Play Store.
But what if you want to view and edit the log files directly on your phone? For that, I recommend Vim Touch, which is a free mobile version of the VIM text editor. I first wrote about this a few years ago, when discussing the best ways to set up a PHP development environment on an Android device.
Before we wrap things up, I want to point out that rooting your phone can result in your phone being more susceptible to malware, and certain applications (especially banking applications) not working.
If you’re considering rooting your device just to get at your log files, I strongly recommend you use the tethered, ADB-based approach instead. It’s just as easy, and way more secure.
Over To You!
Have you ever had to get hold of your phone or tablet’s system log? How come? Did you find it easy? Which method did you use? Let me know in the comments below.