我想从logcat中读取最后n行.这有用吗?:
Process process = Runtime.getRuntime().exec("logcat -t -500");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
...
-t number
使logcat仅从数字和向前指示的位置打印条目.正数表示该位置相对于日志文件的开头,负数表示该位置相对于日志文件的结尾.
谢谢
解决方法:
尝试这样的事情:
String[] command = { "logcat", "-t", "500" };
Process p = Runtime.getRuntime().exec(command);
有关完整示例,请检查Log Collector,它肯定有效:
解释为什么这可以从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'