Search code examples
androidadblogcat

Gathering logs without using adb


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?


Solution

  • 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.