I am trying to troubleshoot a bug on my app, and need to access the logs.
I normally would do this by connecting my device and using adb logcat
(either by USB or WiFi).
The problem I have is, the bug I am looking into is not reproduced when the device is connected to the USB or connected to adb via WiFi. So in other words, I need to view logs, but when I connect adb the bug does not happen.
Does Android store a log buffer on memory that can be downloaded after the fact?
CodePudding user response:
ADB stores the log messages in a small RAM based ring buffer. That means the newest message overwrites the oldest message. If you connect a device via USB and execute adb logcat
logcat first prints all messages from that buffer and then waits for new messages and prints each of them.
Thus if you connect your phone via USB and execute adb logcat
you will get also messages that appeared before you connected your phone via USB.
How many of those "old" messages you can get depends on the number of logcat messages per second and the configured adb logcat buffer size.
The logcat buffer size can be configured in Developer Options as described here.
The number of messages per second can depends on the used device and the number of installed and active apps. Some devices have multiple messages per second (I remember especially Samsung devices having a high frequency of logcat messages). The number of messages can not be configured or directly changed. You can only try to stop/kill or disable apps to reduce the number of messages if you need to.
But usually increasing the logact buffer should be sufficient. So you can reproduce the error, then connect the phone via USB and directly execute adb logcat
. Hopefully the error is then included in logcat output.
CodePudding user response:
Option 1. You can try taking the bug report that is available on the device level, tough it is not the best experience. This is inside "Developer Options" menu.
Option 2. There are many applications available at play store for Logcat. One that I just tried is "Logcat Reader".
Option 3. Requires effort and coding. Switch to a logging library that can write application logs to a file. One famous logging library is Timber, and these are some suggestions how to configure it to log in files: Android: a library to write log on file?