ADB logcat fails to clear the main log - android

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?

Related

How to clean dumpstate/logcat with adb shell?

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.

How to take log while running app in emulator through comand line

I am running my app in emulator through command line referring this link. But i am not able to find any command through which i can take log of the app running on emulator.
The Command to receive the log buffers on commandline is:
[adb] logcat [<option>] ... [<filter-spec>] ...
There are several options that can be passed that can be found here.
For more informations continue reading here:
Logcat Documentation
Reading and Writing Logs

To get complete logs of 2 devices using adb

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.

Logcat displays nothing when used from Runtime.exec

I'm running the command
logcat -d AndroidRuntime:E *:S
When ran from adb on my computer, it displays all the things it should. When I try to run it from an Android application with
Runtime.getRuntime().exec("logcat -d AndroidRuntime:E *:S");
and print the output, it won't display anything except the headers.
How can I fix this?
First, this has never been supported.
Second, if you are running on Android 4.1 and later, you will only get any log messages that your own app logs, not messages from other apps, as you can no longer hold the READ_LOGS permission in an ordinary SDK app.

Where does Android store shutdown logs?

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.

Categories

Resources