Skip to content

Commit

Permalink
[Feat] log uncaught exceptions (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil0v3s authored Oct 27, 2024
1 parent 83526e4 commit 616a539
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Unit>()

registerKeyboardHook { channel.trySend(Unit) }
Expand Down

0 comments on commit 616a539

Please sign in to comment.