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'

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...