How to empty (clear) the logcat buffer in Android [duplicate] - android

This question already has answers here:
How can I erase the old data from logcat?
(4 answers)
Closed 5 years ago.
How can I empty (clear) the logcat buffer in Android?
I use adb logcat from command line and pipe the output to a file, since the DDMS has a very limited buffer. At the moment, when I restart my app (after fixing bugs etc) the logcat buffer has data from the previous launch as well. Even uninstalling the app does not clear the buffer. The only way I've found so far to clear the buffer, is reboot. This is effective, but would like to know if there's an easier way.

adb logcat -c
Logcat options are documented here: http://developer.android.com/tools/help/logcat.html

The following command will clear only non-rooted buffers (main, system ..etc).
adb logcat -c
If you want to clear all the buffers (like radio, kernel..etc), Please use the following commands
adb root
adb logcat -b all -c
or
adb root
adb shell logcat -b all -c
Use the following commands to know the list of buffers that device supports
adb logcat -g
adb logcat -b all -g
adb shell logcat -b all -g

I give my solution for Mac:
With your device connected to the USB port, open a terminal and go
to the adb folder.
Write: ./adb devices
The terminal will show something like this:
List of devices attached
36ac5997 device
Take note of the serial number (36ac5997)
Write: ./adb -s 36ac5997 to connect to the device
Write: ./adb logcat
If at any time you want to clear the log, type ./adb logcat -c

For anyone coming to this question wondering how to do this in Eclipse, You can remove the displayed text from the logCat using the button provided (often has a red X on the icon)

Related

ADB Shell is not displaying logs continously

I am trying to debug a Yocto project. I have flashed cpp binaries on some device.
Now I my trying to display logs using below adb command
adb shell tail -f /var/log/acs_main.log
The problem i'm facing is that logs are not displayed continuously.I have to cancel and again start to print further log statements.
Anyone can help me in this ?

Debugging a WebView (Ionic) app on Android via logcat

There are several questions about the subject, however not one of them seems to address the particular problem I'm having.
I'm developing an app with Cordova/Ionic, and printing debugging info I was outputting with console.log() by using adb logcat CordovaLog:D *:S was working just fine until some updates. Now I can't seem to figure out how to properly filter logcat's output so I could only get the debugging info from my app.
Logging itself works. If I set no filters and redirect output to a file, I can see my debugging info among all the other debug messages, and it looks like this:
I/Web Console: Event triggered: device.ready:1
Logging to screen also works, but at a rate of approximately 100 lines per second. I've tried at least the following to filter output:
adb logcat -s "Web Console"
adb logcat "Web Console":V
adb logcat "Web Console":*
adb logcat -s Web
adb logcat Web:V
adb logcat "myApp":V
adb logcat myApp:V
adb logcat -s myApp
... and probably others I've already forgotten. They either print absolutely nothing, or absolutely everything from the system services.
I'm on Windows so I can't grep, and the device I'm debugging on is running Android 4.2.2 so I can't use GapDebug, and neither does it seem to be possible to access the device's log via chrome://inspect in Chrome.
I really, really would like to understand how filtering logcat's output works. I'm not willing to log everything to a file and then shift through that.
It seems that logcat can not properly parse tag names with whitespaces. So instead I suggest using grep on the device:
adb shell "logcat | grep 'Web Console'"
Alternatively when runing adb on linux or unix based os/git bash:
adb logcat | grep 'Web Console'
What works for me in 2019:
adb -d logcat chromium:I *:S
The -d indicating a physical device in my case. If all else fails just dump the results of adb logcat into a text file and do a search for "CONSOLE", that will give you the provider for your logcat filter. It seems this changes over time, and depending on your particular dev environment.
While you can use grep under Linux/Unix, findstr might be your choice under Windows:
adb logcat | findstr /C:"Web Console"
If you prefer to use grep under Windows, you can get it from
http://gnuwin32.sourceforge.net/packages/grep.htm.

Using ADB to capture the screen [duplicate]

This question already has answers here:
Read binary stdout data like screencap data from adb shell?
(19 answers)
Closed 6 years ago.
I'm trying to get a screenshot of the phone screen as fast as possible.
Currently, I am doing:
adb shell screencap -p /sdcard/screencap.png && adb pull /sdcard/screencap.png
However it is too slow and takes up to 3 seconds.
Is there any better way to do this? I intend to use this function with an unrooted phone.
Also what are the different arguments I can use for screencap?
Thanks.
EDIT (extra information): I intend to use this method to be able to get a live feed of the screen onto my pc. The current method works however it is too slow. I can't use adb shell screenrecord because I won't be able to access the video file while it is being recorded.
To save to a file on Windows, OSX and Linux
adb exec-out screencap -p > screen.png
To copy to clipboard on Linux use
adb exec-out screencap -p | xclip -t image/png
https://stackoverflow.com/a/37191719/75579 answer stopped working for me in Android 7 somehow. So I have to do it the manual way, so I want to share it.
How to install
Put this snippet of code in your ~/.bash_profile or ~/.profile file:
snap_screen() {
if [ $# -eq 0 ]
then
name="screenshot.png"
else
name="$1.png"
fi
adb shell screencap -p /sdcard/$name
adb pull /sdcard/$name
adb shell rm /sdcard/$name
curr_dir=pwd
echo "save to `pwd`/$name"
}
Run source ~/.bash_profile or source ~/.profile command,
How to use
Usage without specifying filename:
$ snap_screen
11272 KB/s (256237 bytes in 0.022s)
Saved to /Users/worker8/desktop/screenshot.png
Usage with a filename:
$ snap_screen mega_screen_capture
11272 KB/s (256237 bytes in 0.022s)
Saved to /Users/worker8/desktop/mega_screen_capture.png
Hope it helps!
** This will not work if multiple devices are plugged in
To start recording your device’s screen, run the following command:
adb shell screenrecord /sdcard/example.mp4
This command will start recording your device’s screen using the default settings and save the resulting video to a file at /sdcard/example.mp4 file on your device.
When you’re done recording, press Ctrl+C in the Command Prompt window to stop the screen recording. You can then find the screen recording file at the location you specified. Note that the screen recording is saved to your device’s internal storage, not to your computer.
The default settings are to use your device’s standard screen resolution, encode the video at a bitrate of 4Mbps, and set the maximum screen recording time to 180 seconds. For more information about the command-line options you can use, run the following command:
adb shell screenrecord --help
This works without rooting the device. Hope this helps.
You can read the binary from stdout instead of saving the png to the sdcard and then pulling it:
adb shell screencap -p | sed 's|\r$||' > screenshot.png
This should save a little time, but not much.
source: Read binary stdout data from adb shell?
Using some of the knowledge from this and a couple of other posts, I found the method that worked the best for me was to:
adb shell 'stty raw; screencap -p'
I have posted a very simple Python script on GitHub that essentially mirrors the screen of a device connected over ADB:
https://github.com/baitisj/android_screen_mirror
Sorry to tell you screencap just a simple command, only accept few arguments, but none of them can save time for you, here is the -h help output.
$ adb shell screencap -h
usage: screencap [-hp] [-d display-id] [FILENAME]
-h: this message
-p: save the file as a png.
-d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.
Besides the command screencap, there is another command screenshot, I don't know why screenshot was removed from Android 5.0, but it's avaiable below Android 4.4, you can check the source from here. I didn't make my comparison which is faster between these two commands, but you can give your try in your real environment and make the final decision.

redirect adb logcat to android avd

i want to redirect the Android developer tools logcat output to a file into the virtual device from a shell command, before than running the android app test.
The command i usually use to redirect the output to a file is:
adb shell logcat -v time - f log.txt packageName:F *:E > /folder/log.txt
but it puts the log file into a computer directory (/folder/ in this case).
I want to change it with a directory in the virtual device but like above, it says the folder does not exist.
There is way to do it via shell command?
You can simply do
adb shell "logcat -v time -f /mnt/sdcard/log.txt packageName:F *:E"
to accomplish it all in one command from the host shell. You do not need the redirect when you use the -f flag, in fact the redirect would not capture anything if you have directed the output of logcat to a file rather than to stdout.
If that is not working, it is either because you are using a version of Android which mounts the external storage at some other path, or you do not have an emulated sdcard attached to your virtual device.
You can investigate either of these problems by examining the output of
adb shell mount
If you do not have an sdcard at all on your AVD, follow the emulator documentation instructions for creating and attaching one.
For testing purposes only there may be other paths than the sdcard at which you can write, particularly on an emulator where the adb shell runs as root, for example on some versions /data/local or similar.
You can try this one adb shell then #logcat>/sdcard/log.txt now i am sure about the results.you just need a command prompt window to be opened for adb shell,that's not so bad i guess.

How can I erase the old data from logcat?

When I execute the command
adb logcat
while running the android emulator, all of the old logs blow past and so I figure they are stored in a file somewhere. Is there a command I can run to clear the logs and start fresh? If not, is there some other way to do this?
Have you tried this?
adb logcat -c
https://developer.android.com/studio/command-line/logcat.html
adb logcat -c
didn't do it for me
adb logcat -b all -c
worked
Dup of
How to empty (clear) the logcat buffer in Android
The following command will clear only non-rooted buffers (main, system ..etc).
adb logcat -c
If you want to clear all the buffers (like radio, kernel..etc), Please use the following commands
adb logcat -b all -c
or
adb root
adb shell logcat -b all -c
For me, adb logcat -c was not working and was giving following error :
failed to clear the 'main' log
For this, I first did :
adb shell
Than I did :
logcat -c
then exit the shell.
This way I was able to clear logcat when same was not getting cleared from adb logcat -c

Categories

Resources