Skip to content

Commit

Permalink
fix: Fix EXCEPTION_ACCESS_VIOLATION in ktor server and log4j2 error
Browse files Browse the repository at this point in the history
  • Loading branch information
zyklone4096 committed Jun 10, 2024
1 parent ce58ce8 commit 9b235a4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "cn.afternode"
version = "1.0-SNAPSHOT"
version = "1.0.1"

repositories {
mavenCentral()
Expand Down Expand Up @@ -39,8 +39,10 @@ compose.desktop {

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb, TargetFormat.Exe)
packageName = "MoeTalkLocal"
packageVersion = "1.0.0"
packageName = "MoeTalkDesktop"
packageVersion = project.version as String

modules("java.management")

windows {
console = true
Expand Down
5 changes: 4 additions & 1 deletion compose-desktop.pro
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-dontwarn org.apache.**
-dontwarn okhttp3.**
-dontwarn io.netty.**
-dontwarn io.netty.**

-keep class org.apache.logging.** { *; }
-keep class org.slf4j.** { *; }
8 changes: 7 additions & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.*
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.config.Configurator
import org.apache.logging.log4j.spi.LoggerContext
import org.slf4j.LoggerFactory
import server.MoeTalk
import server.Server
import ui.ui
import kotlin.system.exitProcess

private val logger = LoggerFactory.getLogger("Main")
val logCtx = Configurator.initialize("MoeTalkDesktop", MoeTalk::class.java.classLoader, "log4j2.xml")
private val logger by lazy { logCtx.getLogger("Main") }

@Composable
@Preview
Expand All @@ -32,6 +37,7 @@ fun App() {
}

fun main() = application {
logger.info("Starting application")
Window(onCloseRequest = ::onExit, title = "MoeTalk Desktop") {
App()
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/server/MoeTalk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package server

import logCtx
import okhttp3.OkHttpClient
import okhttp3.Request
import org.slf4j.LoggerFactory
Expand All @@ -32,7 +33,7 @@ import kotlin.io.path.createDirectories
import kotlin.io.path.exists

object MoeTalk {
val logger = LoggerFactory.getLogger("Installer")
val logger = logCtx.getLogger("Installer")
val installDir by lazy { File("moe-talk") }

var proxyHost: String? = null
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/server/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.routing.*
import logCtx
import org.slf4j.LoggerFactory

object Server {
val logger = LoggerFactory.getLogger("Server")
val logger = logCtx.getLogger("Server")

var port: Int = 8080

Expand All @@ -45,7 +46,9 @@ object Server {
try {
logger.info("Starting server on $port")
engine = embeddedServer(Netty, port = port) {
install(CallLogging)
install(CallLogging) {
disableDefaultColors()
}

routing {
routeMoeTalk()
Expand Down

0 comments on commit 9b235a4

Please sign in to comment.