Programmatically get log cat data

2019-07-15 11:41发布

问题:

i want to get logcat data programmatically i used the below code

 StringBuilder debuglog=new StringBuilder();
        try {
            Process process = Runtime.getRuntime().exec("logcat -d");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;

            while ((line = bufferedReader.readLine()) != null) {

                debuglog.append(line);
                debuglog.append("\r\n");
            }
            } catch (IOException e) {
                e.printStackTrace();
            }

Above code is working fine

This line "logcat -d" shows -d,-w,-i messages

But,my problem is i want to show -e messages

回答1:

To get only ERROR use this:

Process process = Runtime.getRuntime().exec("logcat -d *:E");