When filtering logcat in terminal by using adb it's possible to command like this:
adb logcat -d -T "01-26 00:00:00.000"
And filtering all logs after 01-26 00:00:00.
But it doesn't work in programmatically mode. This is my Kotlin code:
Runtime.getRuntime().exec("logcat -d -T 01-26 00:00:00.000")
What's wrong with this code?
Related
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
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"
I am trying to run logcat in background using adb.
adb shell "logcat -r 2000 -f /data/local/test.log &"
But it does not work. If I do adb shell ps | grep logcat I dont see logcat process running.
Adding nohup seems to work.
adb shell "nohup logcat -r 2000 -f /data/local/test.log &"
If you can't run nohup directly, then you could try this: busybox nohup logcat
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. So it has nohup feature as well and you could use it via busybox if manufacturer turns nohup option on at compile time.
I've been searching for the last week trying to find an answer to this question.
How do I start an Android app with valgrind? I know I can start an app with the 'am' command, but it starts the app and exits.
I'm writing an app that uses the NDK for native C code, and I need to check it for suspected memory errors.
Edit:
I've learned a little more. You can "wrap" an app with a shell script.
Here's the shell script I'm using:
#!/system/bin/sh
VGPARAMS='--error-limit=no'
export TMPDIR=/data/data/com.starlon.froyvisuals
exec /data/local/Inst/bin/valgrind $VGPARAMS $*
And here's setprop:
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper valgrind"
And here's how I start the app:
adb shell am start -n com.starlon.froyvisuals/.FroyVisuals
I don't think this is right, because I'm not sure where the shell script fits in and I'm not seeing anything in logcat. Any hints?
Edit2:
Oh the shell script is indicated with "setprop" command above. So
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper /data/local/val.sh"
I'm still not seeing anything in logcat.
You can try to clear the logcat first
prompt# adb logcat -c
prompt# adb logcat
You should be able to see the logs coming in once you triggered your application.
am start -a android.intent.action.MAIN -n com.example.hellojni/.HelloJni
I had problems with my shell script and i used this instead.
adb shell setprop wrap.com.example.hellojni "logwrapper /data/local/Inst/bin/valgrind"
You should be able to pass in the parameter right after valgrind
I encountered this problem too. In my situation, I edit the "val.sh" in windows & adb push it to the emulator, but the shell script could not be executed correctly. Then I use a echo "*" > val.sh style to make the "val.sh" and It works well.
So you should first make sure the "val.sh" could be interpreted correctly.
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