Taking logcat and kernel logs simultaneously - android

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"

Related

How to do name filter for adb logcat?

I am debugging an apk on phone using cmd. Here are my steps:
adb install -r D:\apk_path
adb logcat
Now I am confused with a whole bunch of log. There I did find:
I/My Kingdom:(28862): Base Age: 33
How to filter all the log with "My Kingdom" name? If possible, please include an option for I/, D/,... too.
use -
adb logcat -s "your tag"
logcat help
multiple filters-
adb logcat -s "tag1","tag2"
You could possibly just use grep:
adb logcat | grep -i "my kingdom"

Send data back to the script which started the activity via adb shell am start

I want to install a diagnostic app from adb and get back data from it from within a bash script. I know how to start an activity from adb, but I can't find any way to get data back unless maybe if I print to logcat and parse the output, but that sounds like a hack. Is there a way to receive data back from an activity started using adb?
If the data that you want to send back to your automation script could be serialized into a string less than 4k long - using logcat is a natural choice.
Just make your activity to print the data to the log with Log.i("UNIQUE_TAG", the_data_string_you_want_to_send_back_to_your_script); and then use the following commands in your automation script to capture the output:
# clear the logcat buffer
adb logcat -c
# start your activity
adb shell am start <INTENT>
# this line will block until a string with "UNIQUE_TAG" tag and "Info" priority
# is printed to the main log
adb shell 'logcat -b main -v raw -s UNIQUE_TAG:I | (read -n 1 && kill -2 $((BASHPID-1)))'
# now you can capture the data and process it
DATA=$(adb logcat -d -b main -v raw -s UNIQUE_TAG:I)
In more recent Android versions (7.0+) where logcat properly supports -m <count>, -t <time> and -T <time> parameters you can use this much simpler version without having to clear the log with logcat -c first:
# instead of clearing the log just get the current timestamp
TS=$(adb shell 'echo $EPOCHREALTIME; log ""')
# start your activity
adb shell am start <INTENT>
# this command will return immediately if the data has been printed already or block if not
DATA=$(adb shell "logcat -b main -T $TS -m 1 -v raw -s UNIQUE_TAG:I")

Android KERN_DEBUG Log Levels

Where are KERN_DEBUG log levels written to in Android? If I were, for example, to call
printk(KERN_DEBUG "666 The beast lives here 666");
then where is the output written?
I figured it out. In Android, output of printk can be read with
$ adb shell cat /proc/kmsg
or, provided a prior log was written to before, then with
$ adb shell /proc/last_kmsg
or with
$ adb shell dmesg

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".

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