I'd like to read the last n lines from logcat. Should this be working?:
Process process = Runtime.getRuntime().exec("logcat -t -500");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
...
-t number
Makes logcat print only entries from the position indicated by number and onward. A positive number indicates that the position is relative to the beginning of the log file, and a negative number indicates that the position is relative to the end of the log file.
Thanks
Try something like this:
String[] command = { "logcat", "-t", "500" };
Process p = Runtime.getRuntime().exec(command);
For a full example check Log Collector, it definitely works:
http://code.google.com/p/android-log-collector/source/browse/trunk/android-log-collector/src/com/xtralogic/android/logcollector/SendLogActivity.java
To explain why this works from logcat man:
-t <count> print only the most recent <count> lines (implies -d)
-t '<time>' print most recent lines since specified time (implies -d)
-T <count> print only the most recent <count> lines (does not imply -d)
-T '<time>' print most recent lines since specified time (not imply -d)
count is pure numerical, time is 'MM-DD hh:mm:ss.mmm'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With