Skip to content
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

Appending text with the SentryFileWriter not possible #387

Closed
Melle010 opened this issue Oct 13, 2022 · 4 comments · Fixed by getsentry/sentry-java#2304
Closed

Appending text with the SentryFileWriter not possible #387

Melle010 opened this issue Oct 13, 2022 · 4 comments · Fixed by getsentry/sentry-java#2304
Labels
bug Something isn't working Platform: Android

Comments

@Melle010
Copy link

Gradle Version

7.3

AGP Version

7.0.3

Code Minifier/Optimizer

Proguard

Version

3.1.5

Sentry SDK Version

6.4.2

Steps to Reproduce

Appending a text to an existing text file overwrites the previous line. As a result, our log files always consist of only one (the most recent) log message. While debugging I noticed that SentryFileWriter is used instead of Java's FileWriter:

Bildschirmfoto 2022-10-13 um 10 08 35

You can test it with the following code:

init {
    appendToLogFile("log message 1")
    appendToLogFile("log message 2")
}

private fun appendToLogFile(message: String) {
    runCatching {
        FileWriter(getLogFile(), true).use {
            it.append("$message\n")
            it.flush()
        }
    }.onFailure {
        Timber.e(it, "Could not write to log file")
    }
}

Expected Result

A text file with the following content:

log message 1
log message 2

Actual Result

A text file with the following content:

log message 2

2022-10-13.txt

@romtsn
Copy link
Member

romtsn commented Oct 13, 2022

Hey thanks for the report and the details, we'll take a look 👍

@romtsn
Copy link
Member

romtsn commented Oct 17, 2022

This is indeed a very nasty bug 🙈 sorry for the troubles caused. The fix is on its way, and we'll release a new version of the gradle plugin to fix the auto-instrumentation as well. Thanks for the comprehensive report!

Repository owner moved this from In Progress to Done in Mobile & Cross Platform SDK Oct 18, 2022
@romtsn
Copy link
Member

romtsn commented Nov 2, 2022

hey @Melle010 we've released version 3.2.1 of the gradle plugin, which bumps sentry-android to 6.6.0 (where the actual fix is), please try it out and let us know if you still have issues. Thanks!

@Melle010
Copy link
Author

Melle010 commented Nov 3, 2022

Hi @romtsn, thank you for the fix. Yes, with gradle plugin version 3.2.1 and sentry-android version 6.6.0 the file writer works again as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Platform: Android
Projects
Archived in project
2 participants