Skip to content

I want to carry the most recent 1000 full logcat logs when Android crashes #4214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MrZhaobh opened this issue May 23, 2025 · 1 comment
Open

Comments

@MrZhaobh
Copy link

Problem Statement

I found that when native crashes, the EventProcessor process will not be triggered, so the logcat I captured is the log of the next startup. The code is as follows. How can I capture the log when the crash occurs and save it, and then report it with the next startup.

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

Solution Brainstorm

No response

@jamescrosswell
Copy link
Collaborator

@MrZhaobh it sounds like what you're after is this (which you can configure in the options):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Status: No status
Development

No branches or pull requests

2 participants