Skip to content

How to report the full logcat when a crash is triggered in Android? #4447

@MrZhaobh

Description

@MrZhaobh

Integration

sentry-android

Build System

Gradle

AGP Version

7.4.2

Proguard

Enabled

Version

4.14.1

Steps to Reproduce

When I use the following code, I find that the log captured is the log after the next startup, not the log when the crash occurs. I hope that when the crash occurs, I can first capture the recent log and save it, and then bring it when the report is triggered next time.

            options.addEventProcessor(new EventProcessor() {
                @Override
                public SentryEvent process(SentryEvent event, Hint hint) {
                    try {
                        String logcatCmd = "logcat -t 200 --pid " + android.os.Process.myPid() + " *:V";
                        Process process = Runtime.getRuntime().exec(logcatCmd);
                        InputStream input = process.getInputStream();
                        FileOutputStream out = context.openFileOutput("sentry_logcat.txt", Context.MODE_APPEND);
                        byte[] buffer = new byte[4096];
                        int bytesRead;
                        while ((bytesRead = input.read(buffer)) != -1) {
                            out.write(buffer, 0, bytesRead);
                        }
                        out.close();
                        input.close();
                        hint.addAttachment(new Attachment(
                                context.getFilesDir().getPath() + "/sentry_logcat.txt",
                                "sentry_logcat.txt",
                                "text/plain"
                        ));
                    } catch (Exception e) {
                        Log.e("Sentry",e.getMessage());
                    }
                    return event;
                }
            });

Expected Result

I hope that when the crash occurs, I can first capture the recent log and save it, and then bring it when the report is triggered next time.

Actual Result

none

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions