How to take logs in Android
Development on Android that happens on various forums on XDA involves a very crucial element i.e. logs. Taking and submitting proper logs with your bug report/ issue helps a lot to the developer to identify the problem and fix it as well.
You might have wondered a lot of times about how to take logs, which logs are required, and all the various other things. This article aims to help you with “How to take logs in Android”.
Setting up ADB
Using adb i.e. Android Debug Bridge on your PC lets you communicate with your Android device. You can it on your PC through Google’s official SDK Platform Tools website. We have a separate tutorial on How to Install ADB on Windows, macOS, and Linux which will help you to setup adb properly. Make sure to take a look at it.
Type of log to take on a particular issue
It’s important to take particular logs on happening of a particular issue. Below are some examples of which logs you should take on happening of a specific event.
Ramoops is a kernel oops/panic logger which gets generated before system crashes. It writes its logs to RAM of the device. In case your device gets stuck at boot loop or keeps getting rebooted on splash screen without proper adb connection, console-ramoops is the log you need to collect. You can collect it from /sys/fs/pstore/. It is highly dependent to be configured properly from Kernel side otherwise you will have issues with it.
Logcat is a command line tool which dumps a log of system messages. It contains stack traces when the device throws an error. This is the type of log which is most usually asked for an issue. It can be collected either by using adb or some app of your choice. A lot of ROMs nowadays provide options to collect it in Developer Settings as well.
Collect logs using adb:
adb logcat > logcat.log
This will export a continuous log. In case you to stop it, you will have to use Ctrl+C. In case you want to export a complete log in one go, use the parameter -d to do that.
adb logcat -d > logcat.log
You can view the complete list of options on the Google official page for logcat.
dmesg command dumps a log of drivers messages buffer of the kernel. This is useful to debug the issues which are most likely related to the device or its sources itself. You will need root access to collect or view dmesg on Android. A lot of Custom ROMs allows you to use adb as root for this purpose. LineageOS is one of them. You can access the related options in Development settings of the device.
adb shell su -c dmesg > dmesg.log
This will export a complete log.
It is important to note that logs must be collected while the issue is happening or just happened. Logs after the issue disappeared, collected after rebooting into a different or new environment are useless.
Android Apps to collect logs
There are a lot of Android apps available over the web which will help you to collect logs in case you can’t access the PC.
Logcat Extreme is probably the most advance logcat/dmesg reader and collector on Play Store. A simple UI with all the features you need. You can download it from Play Store as well as seek support on its XDA Thread as well.
Logcat Reader is also a simple, opensource app aimed to help you read and save logs on your android device without a lot of work. Colors as per code priority in log, dark theme, facility to search and a lot of simple and useful features are there to help you ease your experience.
Logcat [NO ROOT]
Logcat [NO ROOT] allows you to view logs on your Android device with some simple configuration all without requiring any root access. All you need to do is to configure the app properly as stated in Play Store and you are good to go.