Read filtered log cat(Programmatically)?

2019-06-05 13:36发布

How can i read filtered log cat whereLevel is Warning?

That's all i know....

logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});

br = new BufferedReader(new InputStreamReader(logcat.getInputStream()),4*1024);
String line;
  final StringBuilder log = new StringBuilder();
  String separator = System.getProperty("line.separator"); 
    while ((line = br.readLine()) != null)
     {
       log.append(line);
         log.append(separator);
}

3条回答
Luminary・发光体
2楼-- · 2019-06-05 13:57

The -s flag lets you filter logcat output based on tag and level e,w,d,v so you can try modifying your line.

logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d","-s","*:w"});
查看更多
Deceive 欺骗
3楼-- · 2019-06-05 14:16
if (line.contains("WARN")) {
// ...
}
查看更多
劫难
4楼-- · 2019-06-05 14:19
 try {
                  Process process = Runtime.getRuntime().exec("logcat -d");
                  BufferedReader bufferedReader = new BufferedReader(
                  new InputStreamReader(process.getInputStream()));

                  StringBuilder log=new StringBuilder();
                  String line = "";
                  while ((line = bufferedReader.readLine()) != null) {
                    log.append(line);
                  }
                  TextView tv = (TextView)findViewById(R.id.textView1);
                  tv.setText(log.toString());
                } catch (IOException e) {
                }

Hope u get what u want....

查看更多
登录 后发表回答