Switch Kotlin-Logging to KmLogging

This commit is contained in:
Syer10
2022-03-25 22:30:34 -04:00
parent 0852f08a84
commit 7fd9544f3d
34 changed files with 203 additions and 189 deletions

View File

@@ -68,7 +68,7 @@ dependencies {
// Logging
implementation(libs.logging.slf4j.api)
implementation(libs.logging.slf4j.android)
implementation(libs.logging.ktlogging)
implementation(libs.logging.kmlogging)
// Storage
implementation(libs.okio)

View File

@@ -13,12 +13,12 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.lifecycleScope
import ca.gosyer.jui.android.data.notification.Notifications
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.core.prefs.Preference
import ca.gosyer.jui.core.prefs.getAsFlow
import ca.gosyer.jui.data.ui.model.ThemeMode
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.lighthousegames.logging.logging
import java.util.Locale
class App : Application(), DefaultLifecycleObserver {
@@ -55,7 +55,7 @@ class App : Application(), DefaultLifecycleObserver {
try {
Notifications.createChannels(this)
} catch (e: Exception) {
error(e) { "Failed to modify notification channels" }
log.error(e) { "Failed to modify notification channels" }
}
}
@@ -86,5 +86,7 @@ class App : Application(), DefaultLifecycleObserver {
.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
}
protected companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -19,7 +19,6 @@ import ca.gosyer.jui.android.util.notificationBuilder
import ca.gosyer.jui.android.util.notificationManager
import ca.gosyer.jui.core.lang.chop
import ca.gosyer.jui.core.lang.throwIfCancellation
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.core.prefs.getAsFlow
import ca.gosyer.jui.data.base.WebsocketService.Actions
import ca.gosyer.jui.data.base.WebsocketService.Status
@@ -49,11 +48,12 @@ import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.job
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import org.lighthousegames.logging.logging
import java.util.regex.Pattern
class AndroidDownloadService : Service() {
companion object : CKLogger({}) {
companion object {
private var instance: AndroidDownloadService? = null
fun start(context: Context, actions: Actions) {
@@ -72,6 +72,8 @@ class AndroidDownloadService : Service() {
fun isRunning(): Boolean {
return instance != null
}
private val log = logging()
}
private lateinit var ioScope: CoroutineScope
@@ -103,17 +105,15 @@ class AndroidDownloadService : Service() {
if (intent != null) {
val action = intent.action
info("using an intent with action $action")
log.info { "using an intent with action $action" }
when (action) {
Actions.START.name,
Actions.RESTART.name -> startWebsocket()
Actions.STOP.name -> stopSelf()
else -> info("This should never happen. No action in the received intent")
else -> log.info { "This should never happen. No action in the received intent" }
}
} else {
info(
"with a null intent. It has been probably restarted by the system."
)
log.info { "with a null intent. It has been probably restarted by the system." }
startWebsocket()
}
@@ -157,7 +157,7 @@ class AndroidDownloadService : Service() {
.filterIsInstance<Frame.Text>()
.mapLatest(::onReceived)
.catch {
info(it) { "Error running downloader" }
log.warn(it) { "Error running downloader" }
}
.collect()
}
@@ -169,7 +169,7 @@ class AndroidDownloadService : Service() {
}
.catch {
status.value = Status.STOPPED
error(it) { "Error while running websocket service" }
log.warn(it) { "Error while running websocket service" }
stopSelf()
}
.launchIn(ioScope)

View File

@@ -43,7 +43,7 @@ kotlin {
api(libs.ktor.core)
api(libs.ktor.serialization)
api(libs.okio)
api(libs.logging.ktlogging)
api(libs.logging.kmlogging)
api(libs.multiplatformSettings.core)
api(libs.multiplatformSettings.coroutines)
api(libs.multiplatformSettings.serialization)

View File

@@ -1,16 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package ca.gosyer.jui.core.logging
import mu.KLogger
import mu.KotlinLogging
abstract class CKLogger(logger: KLogger) : KLogger by logger {
constructor(func: () -> Unit) : this(kLogger(func))
}
fun kLogger(func: () -> Unit) = KotlinLogging.logger(func)

View File

@@ -7,18 +7,15 @@
package ca.gosyer.jui.core.io
import ca.gosyer.jui.core.build.BuildKonfig
import mu.KotlinLogging
import net.harawata.appdirs.AppDirsFactory
import okio.FileSystem
import okio.Path
import okio.Path.Companion.toPath
private val logger = KotlinLogging.logger {}
val userDataDir: Path by lazy {
AppDirsFactory.getInstance().getUserDataDir(BuildKonfig.NAME, null, null).toPath().also {
if (!FileSystem.SYSTEM.exists(it)) {
logger.info("Attempted to create app data dir, result: {}", FileSystem.SYSTEM.createDirectories(it))
FileSystem.SYSTEM.createDirectories(it)
}
}
}

View File

@@ -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()
}
}

View File

@@ -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)

View File

@@ -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()
}
}

View File

@@ -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()
}
}

View File

@@ -68,7 +68,7 @@ dependencies {
implementation(libs.logging.log4j.api)
implementation(libs.logging.log4j.core)
implementation(libs.logging.log4j.slf4j)
implementation(libs.logging.ktlogging)
implementation(libs.logging.kmlogging)
// Storage
implementation(libs.okio)

View File

@@ -8,7 +8,6 @@ package ca.gosyer.jui.desktop.logging
import ca.gosyer.jui.desktop.build.BuildConfig
import com.github.weisj.darklaf.LafManager
import mu.KotlinLogging
import okio.Path
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
@@ -16,6 +15,7 @@ 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.lighthousegames.logging.logging
import org.slf4j.bridge.SLF4JBridgeHandler
import java.util.logging.LogManager as JLogManager
@@ -103,8 +103,8 @@ fun initializeLogger(loggingLocation: Path) {
handlers.forEach { removeHandler(it) }
addHandler(SLF4JBridgeHandler())
}
val logger = KotlinLogging.logger("UncaughtException")
val log = logging("UncaughtException")
Thread.setDefaultUncaughtExceptionHandler { t, e ->
logger.error(e) { "Uncaught exception in thread [${t.name}@${t.id}]" }
log.error(e) { "Uncaught exception in thread [${t.name}@${t.id}]" }
}
}

View File

@@ -38,7 +38,7 @@ ktor = "1.6.7"
slf4j = "1.7.36"
slf4jAndroid = "1.7.36-0"
log4j = "2.17.2"
ktlogging = "2.1.21"
kmlogging = "1.1.2"
# Storage
okio = "3.0.0"
@@ -124,7 +124,7 @@ logging-slf4j-android = { module = "uk.uuid.slf4j:slf4j-android", version.ref =
logging-log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
logging-log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
logging-log4j-slf4j = { module = "org.apache.logging.log4j:log4j-slf4j-impl", version.ref = "log4j" }
logging-ktlogging = { module = "io.github.microutils:kotlin-logging", version.ref = "ktlogging" }
logging-kmlogging = { module = "org.lighthousegames:logging", version.ref = "kmlogging" }
# Storage
appDirs = { module = "net.harawata:appdirs", version.ref = "appDirs" }

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.categories
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.models.Category
import ca.gosyer.jui.data.server.interactions.CategoryInteractionHandler
import ca.gosyer.jui.uicore.vm.ContextWrapper
@@ -19,6 +18,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class CategoriesScreenViewModel @Inject constructor(
private val categoryHandler: CategoryInteractionHandler,
@@ -47,7 +47,7 @@ class CategoriesScreenViewModel @Inject constructor(
_isLoading.value = false
}
.catch {
info(it) { "Error getting categories" }
log.warn(it) { "Error getting categories" }
_isLoading.value = false
}
.launchIn(scope)
@@ -59,7 +59,7 @@ class CategoriesScreenViewModel @Inject constructor(
newCategories.forEach {
categoryHandler.createCategory(it.name)
.catch {
info(it) { "Error creating category" }
log.warn(it) { "Error creating category" }
}
.collect()
}
@@ -68,35 +68,35 @@ class CategoriesScreenViewModel @Inject constructor(
if (category == null) {
categoryHandler.deleteCategory(originalCategory)
.catch {
info(it) { "Error deleting category $originalCategory" }
log.warn(it) { "Error deleting category $originalCategory" }
}
.collect()
} else if (category.name != originalCategory.name) {
categoryHandler.modifyCategory(originalCategory, category.name)
.catch {
info(it) { "Error modifying category $category" }
log.warn(it) { "Error modifying category $category" }
}
.collect()
}
}
var updatedCategories = categoryHandler.getCategories(true)
.catch {
info(it) { "Error getting updated categories" }
log.warn(it) { "Error getting updated categories" }
}
.singleOrNull()
categories.forEach { category ->
val updatedCategory = updatedCategories?.find { it.id == category.id || it.name == category.name } ?: return@forEach
if (category.order != updatedCategory.order) {
debug { "${category.name}: ${updatedCategory.order} to ${category.order}" }
log.debug { "${category.name}: ${updatedCategory.order} to ${category.order}" }
categoryHandler.reorderCategory(category.order, updatedCategory.order)
.catch {
info(it) { "Error re-ordering categories" }
log.warn(it) { "Error re-ordering categories" }
}
.singleOrNull()
}
updatedCategories = categoryHandler.getCategories(true)
.catch {
info(it) { "Error getting updated categories" }
log.warn(it) { "Error getting updated categories" }
}
.singleOrNull()
}
@@ -144,5 +144,7 @@ class CategoriesScreenViewModel @Inject constructor(
data class MenuCategory(val id: Long? = null, var order: Int, val name: String, val default: Boolean = false)
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -52,7 +52,9 @@ import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import mu.KotlinLogging
import org.lighthousegames.logging.logging
private val log = logging()
@OptIn(DelicateCoroutinesApi::class)
@Composable
@@ -68,9 +70,8 @@ fun CategoriesScreenContent(
) {
DisposableEffect(Unit) {
onDispose {
val logger = KotlinLogging.logger {}
val handler = CoroutineExceptionHandler { _, throwable ->
logger.debug { throwable }
log.warn(throwable) { "Error updating remote categories" }
}
GlobalScope.launch(handler) {
updateRemoteCategories()

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.downloads
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.base.WebsocketService.Actions
import ca.gosyer.jui.data.download.DownloadService
import ca.gosyer.jui.data.models.Chapter
@@ -23,6 +22,7 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class DownloadsScreenViewModel @Inject constructor(
private val downloadService: DownloadService,
@@ -45,7 +45,7 @@ class DownloadsScreenViewModel @Inject constructor(
fun start() {
downloadsHandler.startDownloading()
.catch {
info(it) { "Error starting download" }
log.warn(it) { "Error starting download" }
}
.launchIn(scope)
}
@@ -53,7 +53,7 @@ class DownloadsScreenViewModel @Inject constructor(
fun pause() {
downloadsHandler.stopDownloading()
.catch {
info(it) { "Error stopping download" }
log.warn(it) { "Error stopping download" }
}
.launchIn(scope)
}
@@ -61,7 +61,7 @@ class DownloadsScreenViewModel @Inject constructor(
fun clear() {
downloadsHandler.clearDownloadQueue()
.catch {
info(it) { "Error clearing download" }
log.warn(it) { "Error clearing download" }
}
.launchIn(scope)
}
@@ -69,7 +69,7 @@ class DownloadsScreenViewModel @Inject constructor(
fun stopDownload(chapter: Chapter) {
chapterHandler.stopChapterDownload(chapter)
.catch {
info(it) { "Error stop chapter download" }
log.warn(it) { "Error stop chapter download" }
}
.launchIn(scope)
}
@@ -79,12 +79,12 @@ class DownloadsScreenViewModel @Inject constructor(
.onEach {
chapterHandler.queueChapterDownload(chapter)
.catch {
info(it) { "Error adding download" }
log.warn(it) { "Error adding download" }
}
.collect()
}
.catch {
info(it) { "Error stop chapter download" }
log.warn(it) { "Error stop chapter download" }
}
.launchIn(scope)
}
@@ -96,5 +96,7 @@ class DownloadsScreenViewModel @Inject constructor(
uiScope?.cancel()
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -7,7 +7,6 @@
package ca.gosyer.jui.ui.extensions
import ca.gosyer.jui.core.lang.displayName
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.extension.ExtensionPreferences
import ca.gosyer.jui.data.models.Extension
import ca.gosyer.jui.data.server.interactions.ExtensionInteractionHandler
@@ -26,6 +25,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ExtensionsScreenViewModel @Inject constructor(
private val extensionHandler: ExtensionInteractionHandler,
@@ -66,7 +66,7 @@ class ExtensionsScreenViewModel @Inject constructor(
_isLoading.value = false
}
.catch {
info(it) { "Error getting extensions" }
log.warn(it) { "Error getting extensions" }
emit(emptyList())
_isLoading.value = false
}
@@ -74,39 +74,39 @@ class ExtensionsScreenViewModel @Inject constructor(
}
fun install(extension: Extension) {
info { "Install clicked" }
log.info { "Install clicked" }
extensionHandler.installExtension(extension)
.onEach {
getExtensions()
}
.catch {
info(it) { "Error installing extension ${extension.apkName}" }
log.warn(it) { "Error installing extension ${extension.apkName}" }
getExtensions()
}
.launchIn(scope)
}
fun update(extension: Extension) {
info { "Update clicked" }
log.info { "Update clicked" }
extensionHandler.updateExtension(extension)
.onEach {
getExtensions()
}
.catch {
info(it) { "Error updating extension ${extension.apkName}" }
log.warn(it) { "Error updating extension ${extension.apkName}" }
getExtensions()
}
.launchIn(scope)
}
fun uninstall(extension: Extension) {
info { "Uninstall clicked" }
log.info { "Uninstall clicked" }
extensionHandler.uninstallExtension(extension)
.onEach {
getExtensions()
}
.catch {
info(it) { "Error uninstalling extension ${extension.apkName}" }
log.warn(it) { "Error uninstalling extension ${extension.apkName}" }
getExtensions()
}
.launchIn(scope)
@@ -153,5 +153,7 @@ class ExtensionsScreenViewModel @Inject constructor(
}
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -9,7 +9,6 @@ package ca.gosyer.jui.ui.library
import ca.gosyer.jui.core.lang.getDefault
import ca.gosyer.jui.core.lang.lowercase
import ca.gosyer.jui.core.lang.withDefaultContext
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.library.LibraryPreferences
import ca.gosyer.jui.data.library.model.Sort
import ca.gosyer.jui.data.models.Category
@@ -40,6 +39,7 @@ import kotlinx.coroutines.flow.single
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.toList
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
private typealias CategoryItems = Pair<StateFlow<List<Manga>>, MutableStateFlow<List<Manga>>>
private typealias LibraryMap = MutableMap<Long, CategoryItems>
@@ -104,7 +104,7 @@ class LibraryScreenViewModel @Inject constructor(
}
.catch {
_error.value = it.message
info(it) { "Error getting categories" }
log.warn(it) { "Error getting categories" }
_isLoading.value = false
}
.launchIn(scope)
@@ -181,7 +181,7 @@ class LibraryScreenViewModel @Inject constructor(
id = category.id,
manga = categoryHandler.getMangaFromCategory(category)
.catch {
info { "Error getting manga for category $category" }
log.warn(it) { "Error getting manga for category $category" }
emit(emptyList())
}
.single(),
@@ -206,7 +206,7 @@ class LibraryScreenViewModel @Inject constructor(
updateCategories(getCategoriesToUpdate(mangaId))
}
.catch {
info(it) { "Error removing manga from library" }
log.warn(it) { "Error removing manga from library" }
}
.launchIn(scope)
}
@@ -218,7 +218,7 @@ class LibraryScreenViewModel @Inject constructor(
fun updateLibrary() {
updatesHandler.updateLibrary()
.catch {
info(it) { "Error updating library" }
log.warn(it) { "Error updating library" }
}
.launchIn(scope)
}
@@ -226,10 +226,12 @@ class LibraryScreenViewModel @Inject constructor(
fun updateCategory(category: Category) {
updatesHandler.updateCategory(category)
.catch {
info(it) { "Error updating category" }
log.warn(it) { "Error updating category" }
}
.launchIn(scope)
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -7,7 +7,6 @@
package ca.gosyer.jui.ui.manga
import ca.gosyer.jui.core.lang.withIOContext
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.download.DownloadService
import ca.gosyer.jui.data.models.Category
import ca.gosyer.jui.data.models.Chapter
@@ -38,6 +37,7 @@ import kotlinx.coroutines.flow.single
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class MangaScreenViewModel @Inject constructor(
private val mangaHandler: MangaInteractionHandler,
@@ -93,7 +93,7 @@ class MangaScreenViewModel @Inject constructor(
_categories.value = it
}
.catch {
info(it) { "Error getting categories" }
log.warn(it) { "Error getting categories" }
}
.launchIn(scope)
}
@@ -136,7 +136,7 @@ class MangaScreenViewModel @Inject constructor(
_manga.value = it
}
.catch {
info(it) { "Error getting manga" }
log.warn(it) { "Error getting manga" }
}
.collect()
categoryHandler.getMangaCategories(mangaId)
@@ -144,7 +144,7 @@ class MangaScreenViewModel @Inject constructor(
_mangaCategories.value = it
}
.catch {
info(it) { "Error getting manga" }
log.warn(it) { "Error getting manga" }
}
.collect()
}
@@ -154,7 +154,7 @@ class MangaScreenViewModel @Inject constructor(
async {
_chapters.value = chapterHandler.getChapters(mangaId, refresh)
.catch {
info(it) { "Error getting chapters" }
log.warn(it) { "Error getting chapters" }
emit(emptyList())
}
.single()
@@ -168,7 +168,7 @@ class MangaScreenViewModel @Inject constructor(
if (manga.inLibrary) {
libraryHandler.removeMangaFromLibrary(manga)
.catch {
info(it) { "Error toggling favorite" }
log.warn(it) { "Error toggling favorite" }
}
.collect()
refreshMangaAsync(manga.id).await()
@@ -190,21 +190,21 @@ class MangaScreenViewModel @Inject constructor(
oldCategories.filterNot { it in categories }.forEach {
categoryHandler.removeMangaFromCategory(manga, it)
.catch {
info(it) { "Error removing manga from category" }
log.warn(it) { "Error removing manga from category" }
}
.collect()
}
} else {
libraryHandler.addMangaToLibrary(manga)
.catch {
info(it) { "Error Adding manga to library" }
log.warn(it) { "Error Adding manga to library" }
}
.collect()
}
categories.filterNot { it in oldCategories }.forEach {
categoryHandler.addMangaToCategory(manga, it)
.catch {
info(it) { "Error adding manga to category" }
log.warn(it) { "Error adding manga to category" }
}
.collect()
}
@@ -227,12 +227,12 @@ class MangaScreenViewModel @Inject constructor(
read = !_chapters.value.first { it.chapter.index == index }.chapter.read
)
.catch {
info(it) { "Error toggling read" }
log.warn(it) { "Error toggling read" }
}
.collect()
_chapters.value = chapterHandler.getChapters(manga)
.catch {
info(it) { "Error getting new chapters after toggling read" }
log.warn(it) { "Error getting new chapters after toggling read" }
emit(emptyList())
}
.single()
@@ -250,12 +250,12 @@ class MangaScreenViewModel @Inject constructor(
bookmarked = !_chapters.value.first { it.chapter.index == index }.chapter.bookmarked
)
.catch {
info(it) { "Error toggling bookmarked" }
log.warn(it) { "Error toggling bookmarked" }
}
.collect()
_chapters.value = chapterHandler.getChapters(manga)
.catch {
info(it) { "Error getting new chapters after toggling bookmarked" }
log.warn(it) { "Error getting new chapters after toggling bookmarked" }
emit(emptyList())
}
.single()
@@ -269,12 +269,12 @@ class MangaScreenViewModel @Inject constructor(
manga.value?.let { manga ->
chapterHandler.updateChapter(manga, index, markPreviousRead = true)
.catch {
info(it) { "Error marking previous as read" }
log.warn(it) { "Error marking previous as read" }
}
.collect()
_chapters.value = chapterHandler.getChapters(manga)
.catch {
info(it) { "Error getting new chapters after marking previous as read" }
log.warn(it) { "Error getting new chapters after marking previous as read" }
emit(emptyList())
}
.single()
@@ -287,7 +287,7 @@ class MangaScreenViewModel @Inject constructor(
manga.value?.let { manga ->
chapterHandler.queueChapterDownload(manga, index)
.catch {
info(it) { "Error downloading chapter" }
log.warn(it) { "Error downloading chapter" }
}
.launchIn(scope)
}
@@ -297,7 +297,7 @@ class MangaScreenViewModel @Inject constructor(
chapters.value.find { it.chapter.index == index }
?.deleteDownload(chapterHandler)
?.catch {
info(it) { "Error deleting download" }
log.warn(it) { "Error deleting download" }
}
?.launchIn(scope)
}
@@ -306,7 +306,7 @@ class MangaScreenViewModel @Inject constructor(
chapters.value.find { it.chapter.index == index }
?.stopDownloading(chapterHandler)
?.catch {
info(it) { "Error stopping download" }
log.warn(it) { "Error stopping download" }
}
?.launchIn(scope)
}
@@ -317,5 +317,7 @@ class MangaScreenViewModel @Inject constructor(
data class Params(val mangaId: Long)
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.reader
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.reader.ReaderPreferences
import ca.gosyer.jui.data.server.interactions.ChapterInteractionHandler
import ca.gosyer.jui.ui.reader.loader.TachideskPageLoader
@@ -17,6 +16,7 @@ import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.take
import org.lighthousegames.logging.logging
class ChapterLoader(
private val readerPreferences: ReaderPreferences,
@@ -27,7 +27,7 @@ class ChapterLoader(
return (chapter.state as ReaderChapter.State.Loaded).pages
} else {
chapter.state = ReaderChapter.State.Loading
debug { "Loading pages for ${chapter.chapter.name}" }
log.debug { "Loading pages for ${chapter.chapter.name}" }
val loader = TachideskPageLoader(chapter, readerPreferences, chapterHandler)
@@ -52,5 +52,7 @@ class ChapterLoader(
return chapter.state is ReaderChapter.State.Loaded && chapter.pageLoader != null
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -7,7 +7,6 @@
package ca.gosyer.jui.ui.reader
import ca.gosyer.jui.core.lang.launchDefault
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.core.prefs.getAsFlow
import ca.gosyer.jui.data.models.Chapter
import ca.gosyer.jui.data.models.Manga
@@ -46,6 +45,7 @@ import kotlinx.coroutines.flow.singleOrNull
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ReaderMenuViewModel @Inject constructor(
private val readerPreferences: ReaderPreferences,
@@ -138,19 +138,19 @@ class ReaderMenuViewModel @Inject constructor(
}
fun navigate(page: Int) {
info { "Navigate to $page" }
log.info { "Navigate to $page" }
scope.launch {
_pageEmitter.emit(PageMove.Page(page))
}
}
fun progress(index: Int) {
info { "Progressed to $index" }
log.info { "Progressed to $index" }
_currentPage.value = index
}
fun retry(page: ReaderPage) {
info { "Retrying $page" }
log.info { "Retrying $page" }
chapter.value?.pageLoader?.retryPage(page)
}
@@ -168,7 +168,7 @@ class ReaderMenuViewModel @Inject constructor(
mode
)
?.catch {
info(it) { "Error updating manga reader mode" }
log.warn(it) { "Error updating manga reader mode" }
}
?.collect()
initManga(params.mangaId)
@@ -187,7 +187,7 @@ class ReaderMenuViewModel @Inject constructor(
sendProgress()
initChapters(params.mangaId, prevChapter.chapter.index)
} catch (e: Exception) {
info(e) { "Error loading prev chapter" }
log.warn(e) { "Error loading prev chapter" }
}
}
}
@@ -200,7 +200,7 @@ class ReaderMenuViewModel @Inject constructor(
sendProgress()
initChapters(params.mangaId, nextChapter.chapter.index)
} catch (e: Exception) {
info(e) { "Error loading next chapter" }
log.warn(e) { "Error loading next chapter" }
}
}
}
@@ -212,7 +212,7 @@ class ReaderMenuViewModel @Inject constructor(
}
.catch {
_state.value = ReaderChapter.State.Error(it)
info(it) { "Error loading manga" }
log.warn(it) { "Error loading manga" }
}
.collect()
}
@@ -223,7 +223,7 @@ class ReaderMenuViewModel @Inject constructor(
chapterHandler.getChapter(mangaId, chapterIndex)
.catch {
_state.value = ReaderChapter.State.Error(it)
info(it) { "Error getting chapter" }
log.warn(it) { "Error getting chapter" }
}
.singleOrNull() ?: return
)
@@ -232,7 +232,7 @@ class ReaderMenuViewModel @Inject constructor(
scope.launchDefault {
val chapters = chapterHandler.getChapters(mangaId)
.catch {
info(it) { "Error getting chapter list" }
log.warn(it) { "Error getting chapter list" }
emit(emptyList())
}
.single()
@@ -285,7 +285,7 @@ class ReaderMenuViewModel @Inject constructor(
private fun markChapterRead(mangaId: Long, chapter: ReaderChapter) {
chapterHandler.updateChapter(mangaId, chapter.chapter.index, true)
.catch {
info(it) { "Error marking chapter read" }
log.warn(it) { "Error marking chapter read" }
}
.launchIn(scope)
}
@@ -296,7 +296,7 @@ class ReaderMenuViewModel @Inject constructor(
if (chapter.read) return
chapterHandler.updateChapter(chapter.mangaId, chapter.index, lastPageRead = lastPageRead)
.catch {
info(it) { "Error sending progress" }
log.warn(it) { "Error sending progress" }
}
.launchIn(GlobalScope)
}
@@ -309,7 +309,7 @@ class ReaderMenuViewModel @Inject constructor(
private fun updateLastPageReadOffset(chapter: Chapter, offset: Int) {
chapter.updateRemote(chapterHandler, offset)
.catch {
info(it) { "Error updating chapter offset" }
log.warn(it) { "Error updating chapter offset" }
}
.launchIn(GlobalScope)
}
@@ -321,5 +321,7 @@ class ReaderMenuViewModel @Inject constructor(
data class Params(val chapterIndex: Int, val mangaId: Long)
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -50,7 +50,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ca.gosyer.jui.core.logging.kLogger
import ca.gosyer.jui.core.util.replace
import ca.gosyer.jui.data.models.MangaMeta
import ca.gosyer.jui.data.reader.model.Direction
@@ -61,8 +60,6 @@ import ca.gosyer.jui.uicore.components.Spinner
import ca.gosyer.jui.uicore.resources.stringResource
import kotlin.math.roundToInt
private val logger = kLogger {}
@Composable
fun ReaderSideMenu(
chapter: ReaderChapter,

View File

@@ -8,7 +8,6 @@ package ca.gosyer.jui.ui.reader.loader
import ca.gosyer.jui.core.lang.IO
import ca.gosyer.jui.core.lang.throwIfCancellation
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.reader.ReaderPreferences
import ca.gosyer.jui.data.server.interactions.ChapterInteractionHandler
import ca.gosyer.jui.ui.reader.model.ReaderChapter
@@ -29,6 +28,7 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.lighthousegames.logging.logging
class TachideskPageLoader(
val chapter: ReaderChapter,
@@ -61,7 +61,7 @@ class TachideskPageLoader(
try {
for (priorityPage in channel) {
val page = priorityPage.page
debug { "Loading page ${page.index}" }
log.debug { "Loading page ${page.index}" }
if (page.status.value == ReaderPage.Status.QUEUE) {
chapterHandler
.getPage(chapter.chapter, page.index) {
@@ -78,7 +78,7 @@ class TachideskPageLoader(
page.bitmap.value = null
page.status.value = ReaderPage.Status.ERROR
page.error.value = it.message
info(it) { "Error getting image" }
log.warn(it) { "Error getting image" }
}
.flowOn(Dispatchers.IO)
.collect()
@@ -86,7 +86,7 @@ class TachideskPageLoader(
}
} catch (e: Exception) {
e.throwIfCancellation()
info(e) { "Error in loop" }
log.warn(e) { "Error in loop" }
}
}
}
@@ -187,5 +187,7 @@ class TachideskPageLoader(
channel.close()
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.reader.model
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.models.Chapter
import ca.gosyer.jui.ui.reader.loader.PageLoader
import kotlinx.coroutines.CoroutineScope
@@ -16,6 +15,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import org.lighthousegames.logging.logging
data class ReaderChapter(val chapter: Chapter) {
val scope = CoroutineScope(Dispatchers.Default + Job())
@@ -40,7 +40,7 @@ data class ReaderChapter(val chapter: Chapter) {
fun recycle() {
if (pageLoader != null) {
debug { "Recycling chapter ${chapter.name}" }
log.debug { "Recycling chapter ${chapter.name}" }
}
pageLoader?.recycle()
pageLoader = null
@@ -55,5 +55,7 @@ data class ReaderChapter(val chapter: Chapter) {
class Loaded(val pages: StateFlow<List<ReaderPage>>) : State()
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -37,7 +37,6 @@ import ca.gosyer.jui.core.io.SYSTEM
import ca.gosyer.jui.core.io.copyTo
import ca.gosyer.jui.core.io.saveTo
import ca.gosyer.jui.core.lang.throwIfCancellation
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.server.interactions.BackupInteractionHandler
import ca.gosyer.jui.i18n.MR
import ca.gosyer.jui.ui.base.dialog.getMaterialDialogProperties
@@ -80,6 +79,7 @@ import okio.Path
import okio.Sink
import okio.Source
import okio.buffer
import org.lighthousegames.logging.logging
import kotlin.random.Random
class SettingsBackupScreen : Screen {
@@ -136,7 +136,7 @@ class SettingsBackupViewModel @Inject constructor(
source.saveTo(file)
}
} catch (e: Exception) {
info(e) { "Error creating backup file" }
log.warn(e) { "Error creating backup file" }
_restoreStatus.value = Status.Error
e.throwIfCancellation()
null
@@ -152,7 +152,7 @@ class SettingsBackupViewModel @Inject constructor(
}
}
.catch {
info(it) { "Error importing backup" }
log.warn(it) { "Error importing backup" }
_restoreStatus.value = Status.Error
}
.collect()
@@ -173,7 +173,7 @@ class SettingsBackupViewModel @Inject constructor(
_restoreStatus.value = Status.Success
}
.catch {
info(it) { "Error importing backup" }
log.warn(it) { "Error importing backup" }
_restoreStatus.value = Status.Error
}
.collect()
@@ -211,7 +211,7 @@ class SettingsBackupViewModel @Inject constructor(
backup.content.toSource().saveTo(it)
} catch (e: Exception) {
e.throwIfCancellation()
info(e) { "Error creating backup" }
log.warn(e) { "Error creating backup" }
_creatingStatus.value = Status.Error
_creating.value = false
} finally {
@@ -223,7 +223,7 @@ class SettingsBackupViewModel @Inject constructor(
}
}
.catch {
info(it) { "Error exporting backup" }
log.warn(it) { "Error exporting backup" }
_creatingStatus.value = Status.Error
_creating.value = false
}
@@ -240,7 +240,7 @@ class SettingsBackupViewModel @Inject constructor(
_creatingStatus.value = Status.Success
} catch (e: Exception) {
e.throwIfCancellation()
error(e) { "Error moving created backup" }
log.error(e) { "Error moving created backup" }
_creatingStatus.value = Status.Error
} finally {
_creating.value = false
@@ -259,7 +259,9 @@ class SettingsBackupViewModel @Inject constructor(
object Error : Status()
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}
@Composable

View File

@@ -33,7 +33,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.library.LibraryPreferences
import ca.gosyer.jui.data.library.model.DisplayMode
import ca.gosyer.jui.data.server.interactions.CategoryInteractionHandler
@@ -63,6 +62,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
import kotlin.math.roundToInt
class SettingsLibraryScreen : Screen {
@@ -109,7 +109,7 @@ class SettingsLibraryViewModel @Inject constructor(
_categories.value = it.size
}
.catch {
info(it) { "Error getting categories" }
log.warn(it) { "Error getting categories" }
}
.launchIn(scope)
}
@@ -118,7 +118,9 @@ class SettingsLibraryViewModel @Inject constructor(
fun getDisplayModeChoices() = DisplayMode.values()
.associateWith { stringResource(it.res) }
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}
@Composable

View File

@@ -22,7 +22,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.server.ServerPreferences
import ca.gosyer.jui.data.server.model.Auth
import ca.gosyer.jui.data.server.model.Proxy
@@ -116,8 +115,6 @@ class SettingsServerViewModel @Inject constructor(
fun serverSettingChanged() {
_serverSettingChanged.value = true
}
private companion object : CKLogger({})
}
@Composable

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.sources.browse
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.catalog.CatalogPreferences
import ca.gosyer.jui.data.library.LibraryPreferences
import ca.gosyer.jui.data.library.model.DisplayMode
@@ -23,6 +22,7 @@ import kotlinx.coroutines.flow.singleOrNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SourceScreenViewModel(
private val source: Source,
@@ -126,7 +126,7 @@ class SourceScreenViewModel(
else -> sourceHandler.getPopularManga(source, pageNum.value)
}
.catch {
info(it) { "Error getting source page" }
log.warn(it) { "Error getting source page" }
}
.singleOrNull()
}
@@ -160,5 +160,7 @@ class SourceScreenViewModel(
data class Params(val source: Source, val initialQuery: String?)
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.sources.browse.filter
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.models.sourcefilters.SourceFilter
import ca.gosyer.jui.data.server.interactions.SourceInteractionHandler
import ca.gosyer.jui.ui.sources.browse.filter.model.SourceFiltersView
@@ -23,6 +22,7 @@ import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.supervisorScope
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SourceFiltersViewModel(
private val sourceId: Long,
@@ -87,7 +87,7 @@ class SourceFiltersViewModel(
}
}
.catch {
info(it) { "Error with filters" }
log.warn(it) { "Error with filters" }
}
.launchIn(scope)
}
@@ -103,7 +103,7 @@ class SourceFiltersViewModel(
_loading.value = false
}
.catch {
info(it) { "Error getting filters" }
log.warn(it) { "Error getting filters" }
_loading.value = false
}
.launchIn(scope)
@@ -119,5 +119,7 @@ class SourceFiltersViewModel(
SourceFiltersView(index, sourcePreference)
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -8,7 +8,6 @@ package ca.gosyer.jui.ui.sources.globalsearch
import androidx.compose.runtime.snapshots.SnapshotStateMap
import ca.gosyer.jui.core.lang.IO
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.catalog.CatalogPreferences
import ca.gosyer.jui.data.models.MangaPage
import ca.gosyer.jui.data.models.Source
@@ -35,6 +34,7 @@ import kotlinx.coroutines.supervisorScope
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GlobalSearchViewModel @Inject constructor(
private val sourceHandler: SourceInteractionHandler,
@@ -80,7 +80,7 @@ class GlobalSearchViewModel @Inject constructor(
_isLoading.value = false
}
.catch {
info(it) { "Error getting sources" }
log.warn(it) { "Error getting sources" }
_isLoading.value = false
}
.launchIn(scope)
@@ -109,7 +109,7 @@ class GlobalSearchViewModel @Inject constructor(
}
}
.catch {
info(it) { "Error getting search from ${source.displayName}" }
log.warn(it) { "Error getting search from ${source.displayName}" }
emit(Search.Failure(it))
}
.onEach {
@@ -122,7 +122,7 @@ class GlobalSearchViewModel @Inject constructor(
}
}
.catch {
info(it) { "Error getting sources" }
log.warn(it) { "Error getting sources" }
}
.flowOn(Dispatchers.IO)
.launchIn(scope)
@@ -146,5 +146,7 @@ class GlobalSearchViewModel @Inject constructor(
}
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.sources.home
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.catalog.CatalogPreferences
import ca.gosyer.jui.data.models.Source
import ca.gosyer.jui.data.server.interactions.SourceInteractionHandler
@@ -22,6 +21,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SourceHomeScreenViewModel @Inject constructor(
private val sourceHandler: SourceInteractionHandler,
@@ -65,14 +65,14 @@ class SourceHomeScreenViewModel @Inject constructor(
_isLoading.value = false
}
.catch {
info(it) { "Error getting sources" }
log.warn(it) { "Error getting sources" }
_isLoading.value = false
}
.launchIn(scope)
}
fun setEnabledLanguages(langs: Set<String>) {
info { langs }
log.info { langs }
_languages.value = langs
}
@@ -80,5 +80,7 @@ class SourceHomeScreenViewModel @Inject constructor(
_query.value = query
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.sources.settings
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.models.sourcepreference.SourcePreference
import ca.gosyer.jui.data.server.interactions.SourceInteractionHandler
import ca.gosyer.jui.ui.sources.settings.model.SourceSettingsView
@@ -23,6 +22,7 @@ import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.supervisorScope
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SourceSettingsScreenViewModel @Inject constructor(
private val sourceHandler: SourceInteractionHandler,
@@ -45,7 +45,7 @@ class SourceSettingsScreenViewModel @Inject constructor(
.onEach {
sourceHandler.setSourceSetting(params.sourceId, setting.index, it)
.catch {
info(it) { "Error setting source setting" }
log.warn(it) { "Error setting source setting" }
}
.collect()
getSourceSettings()
@@ -63,7 +63,7 @@ class SourceSettingsScreenViewModel @Inject constructor(
_loading.value = false
}
.catch {
info(it) { "Error setting source setting" }
log.warn(it) { "Error setting source setting" }
_loading.value = false
}
.launchIn(scope)
@@ -75,5 +75,7 @@ class SourceSettingsScreenViewModel @Inject constructor(
SourceSettingsView(index, sourcePreference)
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -6,7 +6,6 @@
package ca.gosyer.jui.ui.updates
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.download.DownloadService
import ca.gosyer.jui.data.models.Chapter
import ca.gosyer.jui.data.server.interactions.ChapterInteractionHandler
@@ -24,6 +23,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdatesScreenViewModel @Inject constructor(
private val chapterHandler: ChapterInteractionHandler,
@@ -81,7 +81,7 @@ class UpdatesScreenViewModel @Inject constructor(
_isLoading.value = false
}
.catch {
info(it) { "Error getting updates" }
log.warn(it) { "Error getting updates" }
if (currentPage.value > 1) {
currentPage.value--
}
@@ -93,7 +93,7 @@ class UpdatesScreenViewModel @Inject constructor(
fun downloadChapter(chapter: Chapter) {
chapterHandler.queueChapterDownload(chapter)
.catch {
info(it) { "Error queueing chapter" }
log.warn(it) { "Error queueing chapter" }
}
.launchIn(scope)
}
@@ -106,7 +106,7 @@ class UpdatesScreenViewModel @Inject constructor(
}
?.deleteDownload(chapterHandler)
?.catch {
info(it) { "Error deleting download" }
log.warn(it) { "Error deleting download" }
}
?.launchIn(scope)
}
@@ -119,10 +119,12 @@ class UpdatesScreenViewModel @Inject constructor(
}
?.stopDownloading(chapterHandler)
?.catch {
info(it) { "Error stopping download" }
log.warn(it) { "Error stopping download" }
}
?.launchIn(scope)
}
private companion object : CKLogger({})
private companion object {
private val log = logging()
}
}

View File

@@ -15,7 +15,6 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.text.input.PasswordVisualTransformation
import ca.gosyer.jui.core.logging.CKLogger
import ca.gosyer.jui.data.server.ServerHostPreferences
import ca.gosyer.jui.data.server.ServerPreferences
import ca.gosyer.jui.data.server.ServerService
@@ -128,7 +127,6 @@ actual class SettingsServerHostViewModel @Inject constructor(
}
}.launchIn(scope)
}
private companion object : CKLogger({})
}
fun LazyListScope.ServerHostItems(