Unverified Commit fe74f29b authored by Pavel's avatar Pavel Committed by GitHub

log render exception via logger interface, check that path (#914)

exists
parent 7a6f62bc
...@@ -10,25 +10,39 @@ internal class RenderExceptionsHandler { ...@@ -10,25 +10,39 @@ internal class RenderExceptionsHandler {
private var output: File? = null private var output: File? = null
@JvmStatic @JvmStatic
fun throwException(message: String) { fun throwException(message: String) {
val exception = RenderException(message)
val systemInfo = systemInfo()
Logger.error(exception) { "Render exception\n $systemInfo" }
if (System.getProperty("skiko.win.exception.logger.enabled") == "true") {
try {
if (output == null) { if (output == null) {
output = File( output = File(
"${SkikoProperties.dataPath}/skiko-render-exception-${ProcessHandle.current().pid()}.log" "${SkikoProperties.dataPath}/skiko-render-exception-${ProcessHandle.current().pid()}.log"
) )
output!!.parentFile.mkdirs()
}
output?.appendText("$systemInfo\n")
output?.appendText(exceptionToString(exception))
} catch (t: Throwable) {
Logger.error(t) { "Failed to write report" }
} }
val exception = RenderException(message)
if (System.getProperty("skiko.win.exception.logger.enabled") == "true") {
writeLog(exception)
} }
throw exception throw exception
} }
private fun writeLog(exception: Exception) { private fun systemInfo(): String {
val outputBuilder = StringBuilder().apply { return StringBuilder().apply {
append("When: ${SimpleDateFormat("dd/M/yyyy hh:mm:ss").format(Date())}\n") append("When: ${SimpleDateFormat("dd/M/yyyy hh:mm:ss").format(Date())}\n")
append("Skiko version: ${Version.skiko}\n") append("Skiko version: ${Version.skiko}\n")
append("OS: $hostFullName\n") append("OS: $hostFullName\n")
append("CPU: ${getNativeCpuInfo()}\n") append("CPU: ${getNativeCpuInfo()}\n")
append("Graphics adapters:\n${getNativeGraphicsAdapterInfo()}\n") append("Graphics adapters:\n${getNativeGraphicsAdapterInfo()}")
}.toString()
}
private fun exceptionToString(exception: Exception): String {
return StringBuilder().apply {
append("Exception message: ${exception.message}\n") append("Exception message: ${exception.message}\n")
append("Exception stack trace:\n") append("Exception stack trace:\n")
val stackTrace = exception.stackTrace.filterIndexed { line, _ -> line > 1 } val stackTrace = exception.stackTrace.filterIndexed { line, _ -> line > 1 }
...@@ -36,8 +50,7 @@ internal class RenderExceptionsHandler { ...@@ -36,8 +50,7 @@ internal class RenderExceptionsHandler {
append("$line\n") append("$line\n")
} }
append("\n\n") append("\n\n")
} }.toString()
output?.appendText(outputBuilder.toString())
} }
} }
} }
......
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