1

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);
}
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Sunny
  • 14,522
  • 15
  • 84
  • 129

4 Answers4

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"});
dudebrobro
  • 1,287
  • 10
  • 17
0
if (line.contains("WARN")) {
// ...
}
Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
0

You can easily filter the line that you want to write like the code below:

  while ((line = bufferedReader.readLine()) != null) {
            if(line.contains("OkHttp")){
            log.append(line.substring(line.indexOf("OkHttp")));
            log.append('\n');}
            else{continue;}
        }
Anice Jahanjoo
  • 7,088
  • 3
  • 20
  • 29
-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) {
                }

Hope u get what u want....

Richa
  • 3,165
  • 1
  • 22
  • 26
  • 2
    is there any difference between codes written above?? I ASKED HOW TO FILTER THAT LOGCAT WHICH I AM READING? WHERE Level level = Level.WARNING; – Sunny Feb 07 '12 at 11:21