Search code examples
adbandroid-logcat

Adb Logcat to print only live traces


I am using following command which prints android device logs from connected device buffer in my desktop.

adb logcat

Now requirement is, i am running a test and want to see the output of current action in logs.

That is i need logs only since when i start logging command.

i don't want logs from the buffer or the logs prior to time when logging is started.

Also i don't want to clear the buffer using -c argument. because somebody (some other process) may need buffered traces during testing

adb logcat --live-trace

Thanks in advance for the help.


Solution

  • i found the perfect way to do it!

    Read current time from the device only.

    adb shell echo $(date +'%Y-%m-%d %H:%M:%S')
    

    Merge the above output with ".000" (just adding milliseconds) and save into some variable say %timestamp%. Then,

    adb logcat -v threadtime - D -T %timestamp%