@@ -2,7 +2,6 @@ package info.hannes.timber
22
33import android.annotation.SuppressLint
44import android.content.Context
5- import android.os.Handler
65import android.util.Log
76import androidx.lifecycle.MutableLiveData
87import java.io.File
@@ -45,12 +44,12 @@ open class FileLoggingTree(externalCacheDir: File, context: Context? = null, fil
4544 else -> " $priority "
4645 }
4746
47+ val writer = FileWriter (file, true )
4848 val textLine = " $priorityText $logTimeStamp$tag$message \n "
49-
50- if (! threadCheck && Thread .currentThread().name == " main" )
51- doFileLogging(textLine)
52- else
53- Handler ().post { doFileLogging(textLine) }
49+ writer.append(textLine)
50+ writer.flush()
51+ writer.close()
52+ lastLogEntry.value = textLine
5453 } catch (e: Exception ) {
5554 // Log to prevent an endless loop
5655 if (! logImpossible) {
@@ -63,20 +62,11 @@ open class FileLoggingTree(externalCacheDir: File, context: Context? = null, fil
6362 super .log(priority, tag, message, t)
6463 }
6564
66- private fun doFileLogging (textLine : String ) {
67- val writer = FileWriter (file, true )
68- writer.append(textLine)
69- writer.flush()
70- writer.close()
71- lastLogEntry.value = textLine
72- }
73-
7465 fun getFileName (): String = file.absolutePath
7566
7667 companion object {
7768 private val LOG_TAG = FileLoggingTree ::class .java.simpleName
7869 private var logImpossible = false
79- var threadCheck = false
8070 val lastLogEntry: MutableLiveData <String > = MutableLiveData <String >()
8171 }
8272}
0 commit comments