-
Notifications
You must be signed in to change notification settings - Fork 527
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
[BUG]: ConsoleLogger overwrites local log file for each line write #5232
Comments
Suggest that this is a good potential starter issue since it should be straightforward to investigate, fix, and add tests for it. |
can i work on this issue @adhiamboperes |
Hi @kmanikanta335. Could you please share an overview of your proposed solution? |
@adhiamboperes
|
@kmanikanta335, you can put up a draft PR with these changes that you have proposed. |
Can I work on this issue as @kmanikanta335 has not posted any PR till now? |
Hi @adhiamboperes can i work on this issue? private fun logToFileInBackground(text: String) {
blockingScope.launch {
if (printWriter == null) {
printWriter = PrintWriter(FileWriter(logDirectory, true)) // Open in append mode
}
printWriter?.println(text)
printWriter?.flush()
}
}
/** Close the log file when logging is finished. */
fun closeLogFile() {
printWriter?.close()
printWriter = null
}
} |
Hi @manas-yu, I have assigned the issue to you. Please feel free to put up a PR! |
… write (oppia#5550) ## Explanation Fix oppia#5232 This PR updates the `ConsoleLogger` class to improve logging functionality. The key changes include: - **Append Mode for Logs**: The `FileWriter` is now opened in append mode, ensuring that new log entries are added to the existing log file instead of overwriting it. - **Long-lived PrintWriter**: A long-lived `PrintWriter` instance has been implemented to enhance performance by reducing the overhead of opening and closing the log file multiple times. - **Close Log File**: A `closeLogFile()` method has been added to properly close the `PrintWriter`, preventing resource leaks after logging is complete. These changes address the issue of logs being overwritten and enhance performance while ensuring proper resource management. ## Essential Checklist - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). --------- Co-authored-by: Adhiambo Peres <[email protected]>
Describe the bug
ConsoleLogger
has support for logging output lines to a local log (rather than just logcat). However, it seems that this is currently configured such that each line will completely overwrite the original log file.Steps To Reproduce
adb logcat | grep org.oppia.android
).$ANDROID_HOME/platform-tools/adb pull /data/data/org.oppia.android/files/oppia_app.log ~/opensource/oppia_app.log
Expected Behavior
All lines should be kept, not just the most recent.
Screenshots/Videos
No response
What device/emulator are you using?
Pixel 6a emulator
Which Android version is your device/emulator running?
SDK 33
Which version of the Oppia Android app are you using?
0.11-dev-80a9a09723
Additional Context
From the logic in
ConsoleLogger
:oppia-android/utility/src/main/java/org/oppia/android/util/logging/ConsoleLogger.kt
Line 108 in 6006277
I suspect this is caused by the open
FileWriter
just always, by default, overwriting the file. We should, instead, open the writer in append mode & add tests to verify that this functionality now works.Also, it's probably a good idea to keep a long-lived
PrintStream
open for the log file rather than reopening it for each line (which is going to be less performant). We should overwrite the file in this case (to avoid indefinitely using more disk space for debug logs). This includes adding tests for verifying that multipleConsoleLogger
instances do overwrite the file from the previous logger.The text was updated successfully, but these errors were encountered: