Gathering logs without using adb - android

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?

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.

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?

Related

App logs are sometimes absent from Android bugreport

I'm trying to get logs from a certain Android application (KDE Connect, if this is relevant), whenever a certain issue/error happens.
When I reproduce the issue first, then connect to the phone over USB (USB debugging enabled) and run adb bugreport to capture a bug report -- I cannot see any logs from the application, in the zip's logcat. (I can see other logs from the issue's timeframe though, even from hours earlier, so this doesn't look like a buffer issue)
When I connect to the phone over USB first (USB debugging enabled), reproduce the issue and then run adb bugreport -- I can see the interesting app logs, even a backtrace of the interesting errors, in the zip's logcat.
So it would appear there is a difference in what gets logged when USB debugging is connected/enabled, versus when it is not. I'm no Android developer but I cannot find any info on this behaviour.
Does anyone have an explanation (and sources)?

How to enable / disable Bluetooth hardware initialization logging on Android?

The short question is: Is there a way to enable / disable logging of the Bluetooth hardware initialization on Android? If so, how?
I'm having two "Samsung Galaxy Tab A 10.5" devices and a BLE app I'm currently working on. The app is working flawlessly on one device. The second device, however, does
not find any Bluetooth devices when scanning.
The issue was discovered about a month ago. Those days a quick look at logcat revealed plenty of HIDL related error messages. Now, a few weeks later, the HIDL messages no longer appear in logcat. However, scanning still doesn't work.
Oddly enough, there's not even a single Bluetooth related message in logcat, which makes debugging this issue a little difficult.
EDIT:
Enabling HCI snoop log just revealed a single error message:
*** command 'lshal debug -E android.hardware.bluetooth#1.0::IBluetoothHci/default' failed: exit code 128
It is obvious that one of the tablets is damaged. Interesting is why the HIDL error messages all out of a sudden stopped showing up, and how to get them back?
The actual problem is that Bluetooth, although initialization finishes without errors, isn't working. The question is, how can an app detect it and warn the user about it?
I thought about detecting malfunctioning Bluetooth by reading the logs: If scanning for Bluetooth devices does not yield any results and if there are some HIDL error messages logged, than the user should be warned that there is something wrong with the device running the app.
Now with the HIDL error messages gone, a different approach is needed. Do you have a better idea how to detect if Bluetooth is functioning?
You can enable bluetooth HCI snoop log in developer options:
device settings -> developer options -> enable bluetooth HCI snoop log.
Detailed instruction - how to enable HCI log.

Logcat shows log messages but application filter does not work in-app

I've been struggling with a logcat bug for some time now. I can see log messages of all the other apps, services, libraries, etc. on my Android phone but I'm not able to filter it to only my application as I could before in Android Studio.
If I select my package name in the drop down and then pair that with Show only selected application, the logcat is empty. If I instead use a saved filter that filters by "LOGTAG" (which is my logtag), it shows me a few log messages that are hours old.
However, if I use the command line and pipe the output: adb logcat | find "LOGTAG" I am able to see my log messages real-time as expected.
I have tried restarting Android Studio, re-installing, restarting adb server, and seating the USB wire properly.

How does Android device monitor enable inspection/dump of webviews?

I'm trying to understand why I get a correct hierarchy dump of a webview after I start the Android device monitor (SDK/tools/monitor.bat) but not before. It's enough to simply start it once, after that I can close it and it still work every time (until I reboot the device). So it must send some kind of command or do something.
This is the command I use:
adb shell uiautomator dump
Before I open Android device monitor:
After I open Android device monitor:
As you can see in the second image I can now see all the different nodes inside the webview.
I tried to look through the console output to see if it send some kind of command to the device but I'm not really sure what I should look for. Anyone have an idea on what it can be?

How do I gain access to the application logs on an Android TV device?

I want to be able to access logcat for an app running on an Android TV device, but the TV only has a USB plug not micro-USB.
The Android TV device is
Running a custom Android 4.2.1 ROM (from manufacturer)
Doesn't provide access to device settings
Only has USB plugs
Environment#getStorageState() is always MEDIA_REMOVED
How can I get access to the application log?
You refer to
access logcat for an app
If "an app" is one that you are developing, then although Android now restricts installed apps from seeing the global logcat output, it still allows you to access data that your own process sends to logcat (whether from your own code, or from framework code that runs within your process). It's a simple matter of getting your app to run the logcat command on the device to send the data to a file, and then uploading that file to a webserver somewhere so you can read it.
(Read logcat programmatically within application gives the general principle, which is to exec the logcat program, and then read its output).
If however you are trying to get the logcat output from all the apps on the device, then getting adb working in some form is your only viable choice.
I assume you can install apps on the device, by placing them on an external website and downloading them using the device's webbrowser, then opening the downloaded file.
Thus you may be able to install a settings app extracted from a 4.2 phone, which might allow you to turn on adb debugging (though as you point out, the physical cabling is unusual).
For those facing a similar issue, the solution I have chosen is as follows:
Created a replacement for Android log that decorates Android log but also logs to a log4j RollingFileAppender. This was necessary because the circular logcat buffer on some of the devices was so small that it only contains 5 minutes of log.
Added a menu action that posted all the log4j log files to a web
server
Added a Servlet to my web server to capture client log files and
write them somewhere meaningful.
This seems to work reasonably well.
Aside from item 1 it is pretty the same as zmarties suggestion.

Categories

Resources