3

How to get log for recent time, for example, for last 5 minutes?

This command in command line

adb logcat -v time | find "E/"

gives error logs for all time.

(It's not interesting to wait several minutes while all logs is displaying)

Thank you very much!

Kiryl Ivanou
  • 1,015
  • 2
  • 12
  • 22

2 Answers2

1

adb logcat -T "$(date +'%m-%d %H:%M:%S.%q' -d '5 minutes ago')"

Caveats:

  • Uses time from host system, not device so if there is drift you have to correct for it
  • Requires a POSIX shell and date command (works on Linux and Mac, not sure windows)
Eric Drechsel
  • 2,694
  • 2
  • 23
  • 24
0

The -v time command displays the date, invocation time, priority/tag, and PID of the process issuing the message. So it is not a filter for the actual timestamp of the log. I do not believe there is a way to do this.

Though, you can clear the log with adb logcat -c.

Bryan
  • 14,756
  • 10
  • 70
  • 125
  • after applying "adb logcat -c" anyway i receive log for all time( – Kiryl Ivanou Jan 29 '16 at 17:04
  • Well, that's strange. What version of Android are you using? Just looking it up now, it looks like this is a known issue for Lollipop: https://code.google.com/p/android/issues/detail?id=78916 – Bryan Jan 29 '16 at 17:07
  • Yes, it seems because of version issue. Mine is 6.0.1 – Kiryl Ivanou Jan 29 '16 at 17:09
  • 1
    And, upon further inspection, I found this as the known workaround: `NOW=$(date +"%m-%d %H:%M:%S.000") ; adb logcat -T "$NOW"`, which may actually be what you were looking for originally. – Bryan Jan 29 '16 at 17:10
  • Also strange, I am on 6.0.1 as well, but it works for me. – Bryan Jan 29 '16 at 17:11
  • By don't say that you also have Nexus 7=)) – Kiryl Ivanou Jan 29 '16 at 17:15
  • Bryan, do you know if it's possible to apply any symbols like '?' or '*' to filter. For example i can filter logs by content like adb logcat -v time | find "20:04" so it shows all logs for time 20:04 – Kiryl Ivanou Jan 29 '16 at 17:16
  • Haha, I do actually, but I was using my Nexus 5X to test just now. – Bryan Jan 29 '16 at 17:17
  • Hm, you could possibly use a `grep` command, let me look into that. – Bryan Jan 29 '16 at 17:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102022/discussion-between-kiryl-ivanou-and-bryan). – Kiryl Ivanou Jan 29 '16 at 17:21