Read filtered log cat(Programmatically)?

做~自己de王妃 提交于 2019-12-23 02:31:45

问题


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);
}

回答1:


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"});



回答2:


if (line.contains("WARN")) {
// ...
}



回答3:


 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....



来源:https://stackoverflow.com/questions/9175040/read-filtered-log-catprogrammatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!