RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 776158
Accepted
Pavel Zlotarenchuk
Pavel Zlotarenchuk
Asked:2020-01-27 00:29:43 +0000 UTC2020-01-27 00:29:43 +0000 UTC 2020-01-27 00:29:43 +0000 UTC

如何在 logcat android 中捕获带有 d 标签的消息?

  • 772

先生们好日子。通常,任务是获取应用程序执行日志并通过邮件将它们发送给开发人员。我认为发送会有问题,但日志不会有问题。有一个代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class GetLogs {

    public static String get(){
        StringBuilder builder = new StringBuilder();
        try {
            Process process = Runtime.getRuntime().exec("logcat -d all");

            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));

            String line;
            while ((line = bufferedReader.readLine()) != null) {
                builder.append(line + "\n");
            }
        } catch (IOException e){
            Log.d("Error getting logs");
        }
        return builder.toString();
    }
}

该类只是捕获并返回日志,问题在于它捕获它们的标签。“logcat -d all”应该捕获所有带有d标签的日志,但是我手动输出的那些日志原则上不会捕获。我这样输出它(好吧,你永远不知道):

Log.d("MyLog","TEST");

上面的方法返回以下内容:

    --------- beginning of system
01-26 08:42:37.797  1813  1827 E ActivityThread: Failed to find provider info for com.google.android.gms.chimera
    --------- beginning of main
01-26 08:42:37.797  1813  1827 I chatty  : uid=10080(tanat.androidtesttask) expire 8 lines
01-26 08:42:37.805  1813  1829 I chatty  : uid=10080(tanat.androidtesttask) expire 1 line
01-26 08:42:37.900  1813  1831 I chatty  : uid=10080(tanat.androidtesttask) expire 24 lines
01-26 08:42:39.136  1813  1832 I chatty  : uid=10080(tanat.androidtesttask) expire 9 lines
01-26 08:43:19.769  1813  1848 I chatty  : uid=10080(tanat.androidtesttask) expire 15 lines
01-26 08:43:20.075  1813  1813 I chatty  : uid=10080(tanat.androidtesttask) expire 6 lines
01-26 08:57:52.638  1974  1974 I chatty  : uid=10080(tanat.androidtesttask) expire 27 lines
01-26 08:57:52.670  1974  1988 E ActivityThread: Failed to find provider info for com.google.android.gms.chimera
01-26 08:57:52.670  1974  1988 I chatty  : uid=10080(tanat.androidtesttask) expire 8 lines
01-26 08:57:52.678  1974  1990 I chatty  : uid=10080(tanat.androidtesttask) expire 1 line
01-26 08:57:52.699  1974  1992 I chatty  : uid=10080(tanat.androidtesttask) expire 39 lines
01-26 08:57:53.029  1974  1993 I chatty  : uid=10080(tanat.androidtesttask) expire 9 lines
01-26 09:02:55.283  2073  2073 I chatty  : uid=10080(tanat.androidtesttask) expire 17 lines
01-26 09:02:55.317  2073  2087 E ActivityThread: Failed to find provider info for com.google.android.gms.chimera
01-26 09:02:55.317  2073  2087 I chatty  : uid=10080(tanat.androidtesttask) expire 8 lines
01-26 09:02:55.322  2073  2089 I chatty  : uid=10080(tanat.androidtesttask) expire 1 line
01-26 09:02:55.347  2073  2091 I chatty  : uid=10080(tanat.androidtesttask) expire 3 lines
     --------- beginning of crash
01-26 09:02:55.355  2073  2073 E AndroidRuntime: FATAL EXCEPTION: main
01-26 09:02:55.355  2073  2073 E AndroidRuntime: Process: tanat.androidtesttask, PID: 2073
01-26 09:02:55.355  2073  2073 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{tanat.androidtesttask/tanat.androidtesttask.activity.MainActivity}: java.lang.ArithmeticException: divide by zero
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.ActivityThread.-wrap11(ActivityThread.java)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5417)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-26 09:02:55.355  2073  2073 E AndroidRuntime: Caused by: java.lang.ArithmeticException: divide by zero
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at tanat.androidtesttask.activity.MainActivity.onCreate(Unknown Source)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:6237)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
01-26 09:02:55.355  2073  2073 E AndroidRuntime:    ... 9 more
01-26 09:03:15.533  2102  2102 I chatty  : uid=10080(tanat.androidtesttask) expir

事实上,如果您添加更多我编写的日志,这就是您所需要的。请告诉我,怎么做?

java
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Nikotin N
    2020-01-30T19:44:51Z2020-01-30T19:44:51Z

    我使用这个构造:

    adb logcat -s "TAGNAME"
    
    • 0

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5