How can I erase the old data from logcat? - android

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

Related

Getting adb logs on PC using a batch file while the Android app is running

I have a created a windows batch file(log.bat) like this below :
adb logcat -c
adb logcat -d > log.txt
But it soon exits whenever I press log.bat command.
I want it to keep recording the logs unless I press ctrl+C.
From doc
-c : Clears (flushes) the entire log and exits.
-d : Dumps the log to the screen and exits.
So, in both cases, the execution stops once you run the logcat command with these options. Try this,
adb logcat -c && adb logcat > log.txt
This won't let the shell execution to be released once it executes logcat -c and will start the next command right after it which is adb logcat > log.txt that is going to write the logcat's log till you hit the Ctrl + c.
It looks problem is using option -d with logcat. Please check usage :
-d Dump the log and then exit (don't block)
Removing it will solve your problem.
I need to create a batch file that can copy a log file to a PC. The batch file I created doesn't work. When I run all the commands manually it works however when putting into a script it hangs. Here are the individual commands:
Try this single line command:
$adb shell run-as com.example.name cat /data/data/com.example.name/files/logfile.log > c:\logs\logfile.log

nohangup using ADB shell

I am trying to do a logcat to a file using adb shell by following command -
adb shell "nohup logcat -f /storage/sdcard0/myLog.txt -v time &"
If I do a ps | grep logcat, I don't see the logcat command. Even I tried to see nohup command, but it is not there. So somehow above command does not work.
However if I perform the command in 2 steps it works fine -
adb shell
nohup logcat -f /storage/sdcard0/myLog.txt -v time &
I can see the process using ps and logcat continues to record to the file even if I disconnect adb shell. Now I would like the first command to work, since I am using python scripts to issue commands via ADB. It is possible to change the python scripts, however I would like to know if I am doing anything wrong in issuing the first command and if it is possible to make it work.
try
adb logcat
not
adb shell logcat

Taking logcat and kernel logs simultaneously

I am trying to take logs (logcat and kmsg) via the following command
"logcat -v time -f /dev/kmsg | cat /proc/"
However I am not sure, where the log file is stored, and what will be its name.
How do I identify it
OK, here are the results of a quick Google search:
Android Logging System
How to get kernel messages from Android?
What I got from those links are:
The last part of your command should actually be cat /proc/kmsg
logcat -v time -f /dev/kmsg writes logcat outputs to kernel message buffer
So,
logcat -v time -f /dev/kmsg | cat /proc/kmsg
will output both logcat and kernel logs to stdout (whatever it is). Probably, you may write the output to a file as follows:
logcat -v time -f /dev/kmsg | cat /proc/kmsg > /sdcard/log.txt
The above worked from adb shell prompt on a rooted Android 4.4.2 device.
Hope this helps.
Here is logcat option for getting kernel logs too
adb logcat -b all
You have not specify the Android version you use, but if you are on 8.1 and above it is perfectly possible to have kernel messages included in logcat output with timestamps.
To have them printed in a file together, please use the following:
$adb logcat -b all -d > logcat_all.txt
And if you want to have the kernel messages with timestamps separately from the other logs use:
$adb logcat -b kernel -d > logcat_kernel.txt
-b <buffer> here specifies which buffers you want to have in the output and one of the possible buffers is kernel, which is not included by default. If you set -b all then you will have all of them together. For more details please refer to logcat --help
-b <buffer>, --buffer=<buffer> Request alternate ring buffer, 'main',
'system', 'radio', 'events', 'crash', 'default' or 'all'.
Multiple -b parameters or comma separated list of buffers are
allowed. Buffers interleaved. Default -b main,system,crash.
Here is a quick way:
adb shell
logcat | cat /proc/kmsg
Just execute the following line and that would show the kernel messages on to the logcat
$ adb shell
$ logwrapper cat /dev/kmsg &
$ logcat
Using below commands:
start cmd.exe /c "adb shell cat /dev/kmsg > kmsg.txt"
start cmd.exe /c "adb logcat -v threadtime > logcat.txt"

Unblocking adb logcat in batch file

i want to have batch file for adb logging , my batch file goes like this
adb root
adb remount
adb shell cd /data/log/
adb shell logcat –v time >log_0.txt
adb shell logcat –v time –b radio >log_radio_0.txt &
adb pull /data/log/
the first logcat is blocking .. so the next logcat does not execute..
Please suggest how to unblock logcat here.
thanks in advance
Try this...
adb shell logcat -d -v time >log_0.txt

how to clean old log from logcat, the logcat -c doesn't work

from cmd:
C:\android-sdk-windows\platform-tools>adb shell
and then logcat -b radio
it prints old historic log. I tried to call logcat -c like this:
1. adb shell
2. logcat -c and it returns no error
3. exit and reenter adb shell
4. logcat -b radio(I got the same with or without step 3)
and it didn't work it always got the old log as well. Any idea what is wrong? Thanks!
"logcat -b radio -c",to chean the old radio log,and then "logcat -b radio".

Categories

Resources