mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2026-01-17 09:12:33 +01:00
Switch Kotlin-Logging to KmLogging
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
package ca.gosyer.jui.data.base
|
||||
|
||||
import ca.gosyer.jui.core.lang.throwIfCancellation
|
||||
import ca.gosyer.jui.core.logging.CKLogger
|
||||
import ca.gosyer.jui.data.build.BuildKonfig
|
||||
import ca.gosyer.jui.data.server.Http
|
||||
import ca.gosyer.jui.data.server.ServerPreferences
|
||||
@@ -25,6 +24,7 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.lighthousegames.logging.logging
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
abstract class WebsocketService(
|
||||
@@ -67,7 +67,7 @@ abstract class WebsocketService(
|
||||
.filterIsInstance<Frame.Text>()
|
||||
.mapLatest(::onReceived)
|
||||
.catch {
|
||||
info(it) { "Error running websocket" }
|
||||
log.warn(it) { "Error running websocket" }
|
||||
}
|
||||
.collect()
|
||||
}
|
||||
@@ -79,7 +79,7 @@ abstract class WebsocketService(
|
||||
}
|
||||
.catch {
|
||||
_status.value = Status.STOPPED
|
||||
error(it) { "Error while running websocket service" }
|
||||
log.warn(it) { "Error while running websocket service" }
|
||||
}
|
||||
.launchIn(GlobalScope)
|
||||
}
|
||||
@@ -100,5 +100,7 @@ abstract class WebsocketService(
|
||||
RESTART
|
||||
}
|
||||
|
||||
private companion object : CKLogger({})
|
||||
private companion object {
|
||||
val log = logging()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
package ca.gosyer.jui.data.download
|
||||
|
||||
import ca.gosyer.jui.core.logging.CKLogger
|
||||
import ca.gosyer.jui.data.base.WebsocketService
|
||||
import ca.gosyer.jui.data.download.model.DownloadChapter
|
||||
import ca.gosyer.jui.data.download.model.DownloadStatus
|
||||
@@ -39,7 +38,7 @@ class DownloadService @Inject constructor(
|
||||
downloadQueue.value = status.queue
|
||||
}
|
||||
|
||||
companion object : CKLogger({}) {
|
||||
companion object {
|
||||
val status = MutableStateFlow(Status.STARTING)
|
||||
val downloadQueue = MutableStateFlow(emptyList<DownloadChapter>())
|
||||
val downloaderStatus = MutableStateFlow(DownloaderStatus.Stopped)
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
package ca.gosyer.jui.data.library
|
||||
|
||||
import ca.gosyer.jui.core.logging.CKLogger
|
||||
import ca.gosyer.jui.data.base.WebsocketService
|
||||
import ca.gosyer.jui.data.library.model.UpdateStatus
|
||||
import ca.gosyer.jui.data.server.Http
|
||||
@@ -18,6 +17,7 @@ import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import org.lighthousegames.logging.logging
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
class LibraryUpdateService @Inject constructor(
|
||||
@@ -32,8 +32,10 @@ class LibraryUpdateService @Inject constructor(
|
||||
|
||||
override suspend fun onReceived(frame: Frame.Text) {
|
||||
val status = json.decodeFromString<UpdateStatus>(frame.readText())
|
||||
info { status }
|
||||
log.info { status }
|
||||
}
|
||||
|
||||
private companion object : CKLogger({})
|
||||
private companion object {
|
||||
private val log = logging()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ package ca.gosyer.jui.data.server
|
||||
import ca.gosyer.jui.core.io.copyTo
|
||||
import ca.gosyer.jui.core.io.userDataDir
|
||||
import ca.gosyer.jui.core.lang.withIOContext
|
||||
import ca.gosyer.jui.core.logging.CKLogger
|
||||
import ca.gosyer.jui.data.build.BuildKonfig
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
@@ -22,12 +21,12 @@ import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.launch
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import mu.KotlinLogging
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import okio.Path.Companion.toPath
|
||||
import okio.buffer
|
||||
import okio.source
|
||||
import org.lighthousegames.logging.logging
|
||||
import java.io.File.pathSeparatorChar
|
||||
import java.io.IOException
|
||||
import java.io.Reader
|
||||
@@ -116,7 +115,7 @@ class ServerService @Inject constructor(
|
||||
return@mapLatest
|
||||
}
|
||||
val handler = CoroutineExceptionHandler { _, throwable ->
|
||||
error(throwable) { "Error launching Tachidesk.jar" }
|
||||
log.error(throwable) { "Error launching Tachidesk.jar" }
|
||||
if (_initialized.value == ServerResult.STARTING || _initialized.value == ServerResult.STARTED) {
|
||||
_initialized.value = ServerResult.FAILED
|
||||
}
|
||||
@@ -124,7 +123,7 @@ class ServerService @Inject constructor(
|
||||
GlobalScope.launch(handler) {
|
||||
val jarFile = userDataDir / "Tachidesk.jar"
|
||||
if (!FileSystem.SYSTEM.exists(jarFile)) {
|
||||
info { "Copying server to resources" }
|
||||
log.info { "Copying server to resources" }
|
||||
withIOContext { copyJar(jarFile) }
|
||||
} else {
|
||||
try {
|
||||
@@ -135,20 +134,20 @@ class ServerService @Inject constructor(
|
||||
}
|
||||
|
||||
if (jarVersion != BuildKonfig.SERVER_CODE) {
|
||||
info { "Updating server file from resources" }
|
||||
log.info { "Updating server file from resources" }
|
||||
withIOContext { copyJar(jarFile) }
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
error(e) {
|
||||
log.error(e) {
|
||||
"Error accessing server jar, cannot update server, ${BuildKonfig.NAME} may not work properly"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val javaPath = getRuntimeJava() ?: getPossibleJava() ?: "java"
|
||||
info { "Starting server with $javaPath" }
|
||||
log.info { "Starting server with $javaPath" }
|
||||
val properties = serverHostPreferences.properties()
|
||||
info { "Using server properties:\n" + properties.joinToString(separator = "\n") }
|
||||
log.info { "Using server properties:\n" + properties.joinToString(separator = "\n") }
|
||||
|
||||
withIOContext {
|
||||
val reader: Reader
|
||||
@@ -158,8 +157,8 @@ class ServerService @Inject constructor(
|
||||
.also {
|
||||
reader = it.inputStream.reader()
|
||||
}
|
||||
info { "Server started successfully" }
|
||||
val logger = KotlinLogging.logger("Server")
|
||||
log.info { "Server started successfully" }
|
||||
val log = logging("Server")
|
||||
reader.useLines { lines ->
|
||||
lines.forEach {
|
||||
if (_initialized.value == ServerResult.STARTING) {
|
||||
@@ -169,15 +168,15 @@ class ServerService @Inject constructor(
|
||||
_initialized.value = ServerResult.FAILED
|
||||
}
|
||||
}
|
||||
logger.info { it }
|
||||
log.info { it }
|
||||
}
|
||||
}
|
||||
if (_initialized.value == ServerResult.STARTING) {
|
||||
_initialized.value = ServerResult.FAILED
|
||||
}
|
||||
info { "Server closed" }
|
||||
log.info { "Server closed" }
|
||||
val exitVal = process?.waitFor()
|
||||
info { "Process exitValue: $exitVal" }
|
||||
log.info { "Process exitValue: $exitVal" }
|
||||
process = null
|
||||
}
|
||||
}
|
||||
@@ -191,5 +190,7 @@ class ServerService @Inject constructor(
|
||||
FAILED;
|
||||
}
|
||||
|
||||
private companion object : CKLogger({})
|
||||
private companion object {
|
||||
private val log = logging()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user