Commit 421b1fcc authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Try writing to log file, do not depend on it

parent b6699f04
Pipeline #7679 passed with stage
in 4 minutes and 12 seconds
......@@ -118,7 +118,7 @@ fun Context.log(e: Throwable, extras: Map<String, String>? = null) {
"${Logger.logFileNameTimeStampFormatter.format(System.currentTimeMillis())}.err"
)
if (errorFile.createNewFile()) {
if (errorFile.tryCreateNewFile()) {
val writer = BufferedWriter(FileWriter(errorFile, false))
writer.write("App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}, Commit: ${BuildConfig.COMMIT_HASH})\n")
writer.write("Android SDK version: ${Build.VERSION.SDK_INT} (${Build.VERSION.RELEASE} - ${Build.VERSION.CODENAME})\n")
......@@ -178,7 +178,7 @@ class Logger private constructor(context: Context) {
"${id}_${logFileNameTimeStampFormatter.format(System.currentTimeMillis())}.log"
)
logDir.mkdirs()
logFile.createNewFile()
logFile.tryCreateNewFile()
fileWriter = BufferedWriter(FileWriter(logFile, false))
log("App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})")
......@@ -306,8 +306,12 @@ class Logger private constructor(context: Context) {
if (printToConsole) {
(oldSystemOut ?: System.out).println(textBuilder)
}
fileWriter.write(textBuilder.toString())
fileWriter.flush()
try {
fileWriter.write(textBuilder.toString())
fileWriter.flush()
} catch (ex:Throwable) {
}
}
}
}
......@@ -322,7 +326,7 @@ class Logger private constructor(context: Context) {
"${id}_${logFileNameTimeStampFormatter.format(System.currentTimeMillis())}.err"
)
if (errorFile.createNewFile()) {
if (errorFile.tryCreateNewFile()) {
val writer = BufferedWriter(FileWriter(errorFile, false))
writer.write("App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})\n")
writer.write("Android SDK version: ${Build.VERSION.SDK_INT} (${Build.VERSION.RELEASE} - ${Build.VERSION.CODENAME})\n")
......@@ -340,6 +344,14 @@ class Logger private constructor(context: Context) {
}
}
fun File.tryCreateNewFile():Boolean {
return try {
createNewFile()
} catch (ex:Throwable) {
false
}
}
fun Context.zipAllLogFiles(): File? {
val dir = Logger.getLogDir(this)
if (!dir.canWrite() || !dir.canRead()) return null
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment