1

我如何阅读过滤后的日志猫Level警告在哪里?

这是我所知道的一切....

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

4 回答 4

1

-s 标志允许您根据标记和级别 e、w、d、v 过滤 logcat 输出,以便您可以尝试修改您的行。

logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d","-s","*:w"});
于 2013-01-04T14:50:33.513 回答
0
if (line.contains("WARN")) {
// ...
}
于 2012-05-14T06:44:03.487 回答
0

您可以像下面的代码一样轻松过滤要编写的行:

  while ((line = bufferedReader.readLine()) != null) {
            if(line.contains("OkHttp")){
            log.append(line.substring(line.indexOf("OkHttp")));
            log.append('\n');}
            else{continue;}
        }
于 2021-02-07T07:33:27.587 回答
-1
 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) {
                }

希望你能得到你想要的......

于 2012-02-07T11:11:52.720 回答