From 616a539c06d270b24532eb10f3af4975b3a88d5f Mon Sep 17 00:00:00 2001 From: Danilo Lemes <13068064+Danil0v3s@users.noreply.github.com> Date: Sun, 27 Oct 2024 22:21:35 +0000 Subject: [PATCH] [Feat] log uncaught exceptions (#25) --- .../br/com/firstsoft/target/server/ServerMain.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target/server/src/main/kotlin/br/com/firstsoft/target/server/ServerMain.kt b/target/server/src/main/kotlin/br/com/firstsoft/target/server/ServerMain.kt index e33559e..de1a2e4 100644 --- a/target/server/src/main/kotlin/br/com/firstsoft/target/server/ServerMain.kt +++ b/target/server/src/main/kotlin/br/com/firstsoft/target/server/ServerMain.kt @@ -39,6 +39,7 @@ import java.awt.GraphicsEnvironment import java.awt.Toolkit import java.awt.event.ComponentAdapter import java.awt.event.ComponentEvent +import java.io.File val positions = listOf( Alignment.TopStart, @@ -78,7 +79,17 @@ private fun registerKeyboardHook(onHotkey: () -> Unit) { }) } +private fun writeToFile(exception: Throwable) { + try { + File("cleanmeter.error.${System.currentTimeMillis()}.log").printWriter().use { it.print(exception.stackTraceToString()) } + } catch (e: Exception) { + e.printStackTrace() + } +} + fun main() { + Thread.setDefaultUncaughtExceptionHandler { thread, throwable -> writeToFile(throwable) } + val channel = Channel() registerKeyboardHook { channel.trySend(Unit) }