微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 从logcat读取最后N行?

我想从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,它肯定有效:

http://code.google.com/p/android-log-collector/source/browse/trunk/android-log-collector/src/com/xtralogic/android/logcollector/SendLogActivity.java

解释为什么这可以从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'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐