diff --git a/build.gradle.kts b/build.gradle.kts index 54856104..d843b46f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,6 +63,9 @@ dependencies { implementation("io.ktor:ktor-client-websockets:$ktorVersion") // Logging + val slf4jVersion = "1.7.31" + implementation("org.slf4j:slf4j-api:$slf4jVersion") + implementation("org.slf4j:jul-to-slf4j:$slf4jVersion") val log4jVersion = "2.14.1" implementation("org.apache.logging.log4j:log4j-api:$log4jVersion") implementation("org.apache.logging.log4j:log4j-core:$log4jVersion") diff --git a/src/main/kotlin/ca/gosyer/core/logging/LoggingSetup.kt b/src/main/kotlin/ca/gosyer/core/logging/LoggingSetup.kt index cbc48751..28b4d4af 100644 --- a/src/main/kotlin/ca/gosyer/core/logging/LoggingSetup.kt +++ b/src/main/kotlin/ca/gosyer/core/logging/LoggingSetup.kt @@ -6,13 +6,18 @@ package ca.gosyer.core.logging +import ca.gosyer.BuildConfig +import com.github.weisj.darklaf.LafManager +import mu.KotlinLogging import org.apache.logging.log4j.Level import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.core.LoggerContext import org.apache.logging.log4j.core.appender.ConsoleAppender import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory +import org.slf4j.bridge.SLF4JBridgeHandler import java.io.File +import java.util.logging.LogManager as JLogManager const val consolePattern = "%highlight{%d{" + '$' + "{LOG_DATEFORMAT_PATTERN:-HH:mm:ss.SSS}} [%t] " + '$' + "{LOG_LEVEL_PATTERN:-%p}/%c{1}: %m%n" + '$' + "{LOG_EXCEPTION_CONVERSION_WORD:-%xEx}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=black, DEBUG=black, TRACE=black}" @@ -73,4 +78,21 @@ fun initializeLogger(loggingLocation: File) { } ctx.configuration = builder.build() ctx.updateLoggers() + + // Initialize Darklaf logger + LafManager.setLogLevel( + if (BuildConfig.DEBUG) { + java.util.logging.Level.FINE + } else { + java.util.logging.Level.WARNING + } + ) + JLogManager.getLogManager().getLogger("com.github.weisj.darklaf").apply { + handlers.forEach { removeHandler(it) } + addHandler(SLF4JBridgeHandler()) + } + val logger = KotlinLogging.logger("UncaughtException") + Thread.setDefaultUncaughtExceptionHandler { t, e -> + logger.error(e) { "Uncaught exception in thread [${t.name}@${t.id}]" } + } } diff --git a/src/main/kotlin/ca/gosyer/ui/main/main.kt b/src/main/kotlin/ca/gosyer/ui/main/main.kt index 6878db59..e3b6b661 100644 --- a/src/main/kotlin/ca/gosyer/ui/main/main.kt +++ b/src/main/kotlin/ca/gosyer/ui/main/main.kt @@ -42,7 +42,6 @@ import toothpick.configuration.Configuration import toothpick.ktp.KTP import toothpick.ktp.extension.getInstance import java.io.File -import java.util.logging.Level @OptIn(DelicateCoroutinesApi::class) fun main() { @@ -78,13 +77,6 @@ fun main() { ThemeMode.Light -> IntelliJTheme() ThemeMode.Dark -> DarculaTheme() } - LafManager.setLogLevel( - if (BuildConfig.DEBUG) { - Level.FINE - } else { - Level.WARNING - } - ) withUIContext { LafManager.install(theme) }