Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
manas-yu committed Oct 11, 2024
1 parent 71fc4e9 commit 45dd3a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ConsoleLogger @Inject constructor(
*/
val logErrorMessagesFlow: SharedFlow<ConsoleLoggerContext> = _logErrorMessagesFlow

/** Long-lived PrintWriter to improve performance by not reopening the file every time */
private var printWriter: PrintWriter? = null

/** Logs a verbose message with the specified tag. */
Expand Down Expand Up @@ -136,15 +135,15 @@ class ConsoleLogger @Inject constructor(
private fun logToFileInBackground(text: String) {
blockingScope.launch {
if (printWriter == null) {
printWriter = PrintWriter(FileWriter(logDirectory, true)) // Open in append mode
printWriter = PrintWriter(FileWriter(logDirectory, true)) // Open in append mode.
}
printWriter?.println(text)
printWriter?.flush()
}
}

/** Close the log file when logging is finished. */
fun closeLogFile() {
private fun closeLogFile() {
printWriter?.close()
printWriter = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ConsoleLoggerTest {
fun setUp() {
setUpTestApplicationComponent()
logFile = File(context.filesDir, "oppia_app.log")
logFile.delete() // Ensure we start with a clean log file
logFile.delete() // Ensure we start with a clean log file.
}

@Test
Expand Down

0 comments on commit 45dd3a0

Please sign in to comment.