I'm looking for the log file(s) that are made by logcat. Where are they typically stored?
They are stored as circular memory buffers on the device. If you run "adb logcat > myfile" on your host system, you can retrieve the content into a file.
To get post-mortem information from a device it is helpful to see the timestamp as well. To let you know when the event occurred, try:
adb logcat -d -v time > logfile.txt
If you just want to see the current contents of the log, you can do
adb logcat -d > myfile
It will exit after dumping the log.
(suravi's suggestion would be good if you wanted to watch the log while testing.)
Related
When I connect to a device or an emulator using adb, I can clear logcat using adb logcat -c. The issue I am facing is that I often get the following message:
failed to clear the 'main' log
AFAIK, 'main' is a non-rooted buffer which means that I should be able to clear it without root. What can then be the reason for this message?
You might have your Android Studio opened, please close it and run again , it should able to clear the logs.
use
adb logcat -b all -c
it will clear all buffers. sometime adb logcat -c will not work because of many process using it like android studio.
Logcat messages are stored in buffer, you can try,
adb logcat -c
Clear (flush) the selected buffers and exit. The default buffer set is main, system and crash. To clear all of the buffers, use -b all -c.
source: logcat doc
For more logcat usage, check How do I get the logfile from an Android device?
Is there anyway to clean dumpstate/logcat data with an adb shell? *#9900# is not working on my phone.
I tried adb logcat -c, but it didn't help.
I m struggling with an "Insufficient memory space" problem and cannot install any new apps. I have 5gb of those files and cannot get rid of them :P
When you are using adb logcat -c
-c : clear (flush) the entire log and exit
This a just clears the current buffer of the logcat, but the logs you are referring to aren't created by Logcat but rather by system itself. It should be located under /data/log and this have root permissions. You can delete it if your device is rooted.
If unrooted, you can try to go to settings>storage>cache to clear the cache and see if this helps. I don't know if this can help removing the files, this is a ROM bug, I don't know if there is any available solution without rooting.
Android Studio's logcat is unusable; it goes in and out and rarely shows messages on restart, so I've started using adb logcat on my terminal. Reading http://developer.android.com/tools/debugging/debugging-log.html gives examples of filtering with a tag. What if I don't know the tag, but want to show all error with an error substring I know?
You can always simply pipe the logcat to grep:
$ adb logcat | grep 'known error substring'
If you are on Windows, then use find instead:
C:\> adb logcat | find 'known error substring'
You can try pidcat (by Jake Wharton).
It's a "colored logcat script which only shows log entries for a specific application package", as the author says.
If you're on windows, you can clic on left upper corner > Edit > Search and then introduce the substring you know.
Most probably the terminal for Linux has the same feature, but I don't know how to access to it.
I am testing an app with 2 devices communicating using sockets and monitoring the timestamp values. I select the required device name from the DDMS perspective. But some initial logs are missing(as I have many Log.d statements in the code). I want to store the whole log file after I stop apps in both the phones. Can someone tell me how this can be done in command line using adb? I couldn't find any example for 2 devices.
Thanks
You can try with two console and get logcat separately for two devices
Get serial no for each devices using adb devices
and save logcat as text files
console 1: adb -s <device1serialNO> logcat -d > logcat1.txt
console 2: adb -s <device2serialNO> logcat -d > logcat2.txt
You can filter result for your given tag if needed
Before launching your application you can start the following command in your terminal:
adb logcat <your_application_log_tag>:V *:S > file.txt
<your_application_log_tag> is a log tag that you use in your application. *:S means that you suppress all log outputs from other components. > file.txt redirects the output of the command to file.txt.
The cause of the problem is that for logging Android has a buffer in RAM and if it becomes full it rewrites the most old entries (FIFO). The command I've provided will store the log on your computer.
I know that the boot up log can be obtained by pulling out contents of kmsg or dmesg through ADB.
But I'm not aware of how to retrieve the shutdown logs in Android as there's no /var folder in Android (place where most desktop linux distros generally store their shutdown logs).
So how can I obtain the shutdown logs in Android?
Look in some locations such as these:
/proc/last_kmsg
/data/tombstones/
/data/dontpanic/
/data/system/dropbox/
(This list isn't strictly kernel logs, including framework and application logs too, which are also sometimes of interest)
One work around I found for collecting shutdown logs in Android is to run adb pull /proc/kmsg C:\Logs.txt on the host PC and then switch off the device. You will get the logs till the USB communication between the host and the device snaps! I know this is only one case out of the numerous shutdown scenarios but I haven't found satisfactory answers for other cases!
TL;DR:
Run command through adb that copies logcat and proc/kmsg to a file and keep it running even when adb disconnects with nohup, disown or setsid. Probably needs busybox, needs root and adb root, too.
setsid cat proc/kmsg > /sdcard/kmsg.txt &
and
logcat -v long -f /sdcard/logcat.txt (somehow only works without setsid)
Or add normal copy commands to some startup script.
/TL;DR
You can constantly copy proc/kmsg and logcat to a file on your android device or a microSD card to get the logs even after adb disconnects.
You need root access and adb root access for this to work. For the latter, use the setting in the developer options if you have a custom rom or the adbd insecure app.
After using adb shell to get your android shell, type su to get superuser access.
Then you not only need to put an ampersand (&) after the command but also make sure that the command keeps running after adb disconnects. That is done by nohup, disown or setsid (see here for usage).
If it doesn't work because you don't have these commands, you need to install busybox.
See my question here.
See here for how to get logcat and kernel logs and print it to some file or merge it.
See developer.android.com/tools/help/logcat.html for parameters for the logcat command.
In the end you could have a command like setsid cat proc/kmsg > /sdcard/kmsg.txt & for the kernel messages.
For logcat you could have one of the following commands: logcat -v long -f /sdcard/logcat.txt or logcat -v long > /sdcard/logcat.txt
I don't know why, but sometimes it didn't work with setsid and just didn't copy continuously but stopped shortly after executing the command. In these situations, it also showed up when entering jobs, which it didn't otherwise. Then it just worked without setsid, it stayed alive after disconnecting and reconnecting. I guess you must just try when the file does keep getting larger. If someone figured out why it is behaving like it is... let me know and I'll edit the answer.
Probably adding the commands to a startup script could be a solution for some, too.
Hope this helps.
fightcookie
Newer phones do NOT use any of these locations so if you're reading this article then as of now
The kernel crash logs are now in /sys/fs/pstore instead of /proc/last_kmsg
I was looking for the same thing, and finally, I found the answer!
In android 8 all logs are located in \data\log\android_logs\... including apps and kernel logs. Kernel logs are called kmsgcat-log_timestamp_.gz
edit: Although this is a very old thread, I think the answer might be helpful.