Skip to content

Commit

Permalink
log render exception via logger interface, check that path (#914)
Browse files Browse the repository at this point in the history
exists
  • Loading branch information
SergeevPavel committed Apr 17, 2024
1 parent 7a6f62b commit fe74f29
Showing 1 changed file with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,47 @@ internal class RenderExceptionsHandler {
private var output: File? = null
@JvmStatic
fun throwException(message: String) {
if (output == null) {
output = File(
"${SkikoProperties.dataPath}/skiko-render-exception-${ProcessHandle.current().pid()}.log"
)
}
val exception = RenderException(message)
val systemInfo = systemInfo()
Logger.error(exception) { "Render exception\n $systemInfo" }

if (System.getProperty("skiko.win.exception.logger.enabled") == "true") {
writeLog(exception)
try {
if (output == null) {
output = File(
"${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" }
}
}
throw exception
}

private fun writeLog(exception: Exception) {
val outputBuilder = StringBuilder().apply {
private fun systemInfo(): String {
return StringBuilder().apply {
append("When: ${SimpleDateFormat("dd/M/yyyy hh:mm:ss").format(Date())}\n")
append("Skiko version: ${Version.skiko}\n")
append("OS: $hostFullName\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 stack trace:\n")
val stackTrace = exception.stackTrace.filterIndexed { line, _ -> line > 1 }
for(line in stackTrace) {
append("$line\n")
}
append("\n\n")
}
output?.appendText(outputBuilder.toString())
}.toString()
}
}
}
Expand Down

0 comments on commit fe74f29

Please sign in to comment.