以编程方式应用 logcat 过滤器

发布于 2025-01-05 20:09:36 字数 880 浏览 0 评论 0原文

我需要以编程方式使用过滤器转储 logcat。我应用了 adb logcat -s "TAGNAME" 但应用程序只是“挂起”。有一个类似的线程,但没有解决方案:读取过滤的日志猫(以编程方式)?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二手情话 2025-01-12 20:09:36

我正在使用另一种方式来让我的应用程序运行。这是代码,以防有人想知道。

    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) {

    }

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) {

    }
雨巷深深 2025-01-12 20:09:36

首先,这个命令将流式传输 logcat 并且不会转储它。因此它永远不会停止运行。另外,如果没有内容要报告,BufferedReader 可能正在等待整行输入,因此您会阻塞。

Well first off this command will stream logcat and won't dump it. Hence it will never quit running. Also, if there is no content to report the BufferedReader is probably waiting for a full line to come in, so you are blocking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文