应用logcat的过滤器编程 [英] applying logcat filter programmatically

查看:144
本文介绍了应用logcat的过滤器编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要过滤倾倒logcat的编程。我申请亚行logcat -s变量名,但应用程序只是挂。有一个类似的线程,但有没有办法解决:<一href=\"http://stackoverflow.com/questions/9175040/read-filtered-log-catprogrammatically#comment11543448_9175040\">Read过滤日志猫(编程)?

  {尝试
            工艺过程=调用Runtime.getRuntime()EXEC(logcat的-s XXX)。
            的BufferedReader的BufferedReader =新的BufferedReader(
                    新的InputStreamReader(process.getInputStream()));            StringBuilder的日志=新的StringBuilder();
            串线;
            而((行= bufferedReader.readLine())!= NULL){
                log.append(线);
                log.append(FragmentLog.LINE_SEPARATOR);
            }            ((的TextView)TV).setText(log.toString());        }赶上(IOException异常五){
            ((的TextView)TV).setText(R.string.default_blank);
        }


解决方案

我是用另一种方式来获得我的应用程序的工作。这里是code,如果有人想知道,。

  {尝试
        工艺过程=调用Runtime.getRuntime()EXEC(logcat的-d);
        的BufferedReader的BufferedReader =新的BufferedReader(新的InputStreamReader(process.getInputStream()));        串线;        模式模式= Pattern.compile(XXX,0);        而((行= bufferedReader.readLine())!= NULL){
            如果(patternu!= NULL
                    &功放;&安培; !pattern.matcher(线).find()){
                继续;
            }
            log.append(线);
            log.append('\\ n');
        }    }赶上(IOException异常五){    }

I need to dump logcat with filter programmatically. I applied adb logcat -s "TAGNAME" but the app just "hung". there is a similar thread but there is no solution: Read filtered log cat(Programmatically)?

        try {
            Process process = Runtime.getRuntime().exec("logcat -s XXX");
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));

            StringBuilder log = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                log.append(line);
                log.append(FragmentLog.LINE_SEPARATOR);
            }

            ((TextView) tv).setText(log.toString());

        } catch (IOException e) {
            ((TextView) tv).setText(R.string.default_blank);
        }

解决方案

I am using another way to get my app work. Here is the code, in case anyone wants to know,.

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

        String line;

        Pattern pattern = Pattern.compile("XXX", 0);

        while ((line = bufferedReader.readLine()) != null) {
            if (patternu != null
                    && !pattern.matcher(line).find()) {
                continue;
            }
            log.append(line);
            log.append('\n');
        }

    } catch (IOException e) {

    }

这篇关于应用logcat的过滤器编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆