chore: move logging in kotlin code to Log object

This commit is contained in:
Johannes Frohnmeyer 2023-08-19 15:53:09 +02:00
parent 502026bb22
commit 5b79987dcf
Signed by: Johannes
GPG Key ID: E76429612C2929F4
14 changed files with 41 additions and 25 deletions

View File

@ -3,6 +3,7 @@ package io.gitlab.jfronny.inceptum.gtk
import io.gitlab.jfronny.commons.StringFormatter
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Log
import io.gitlab.jfronny.inceptum.gtk.window.dialog.MicrosoftLoginDialog
import io.gitlab.jfronny.inceptum.gtk.window.dialog.StringInputDialog
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv.EnvBackend
@ -16,7 +17,7 @@ object GtkEnvBackend : EnvBackend {
var dialogParent: Window? = null
override fun showError(message: String, title: String) {
Utils.LOGGER.error(message)
Log.error(message)
simpleDialog(message, title, null, null)
}
@ -25,12 +26,12 @@ object GtkEnvBackend : EnvBackend {
}
override fun showInfo(message: String, title: String) {
Utils.LOGGER.info(message)
Log.info(message)
simpleDialog(message, title, null, null)
}
override fun showOkCancel(message: String, title: String, ok: Runnable, cancel: Runnable, defaultCancel: Boolean) {
Utils.LOGGER.info(message)
Log.info(message)
simpleDialog(message, title, ok, cancel)
}
@ -117,7 +118,7 @@ object GtkEnvBackend : EnvBackend {
}
ResponseType.DELETE_EVENT -> dialog.destroy()
else -> Utils.LOGGER.error("Unexpected response type: $responseId")
else -> Log.error("Unexpected response type: $responseId")
}
}
}

View File

@ -3,6 +3,7 @@ package io.gitlab.jfronny.inceptum.gtk
import io.gitlab.jfronny.inceptum.common.BuildMetadata
import io.gitlab.jfronny.inceptum.common.MetaHolder
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.util.Log
import io.gitlab.jfronny.inceptum.gtk.window.MainWindow
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv
import io.gitlab.jfronny.inceptum.launcher.api.account.AccountManager
@ -19,8 +20,8 @@ object GtkMain {
@JvmStatic
fun main(args: Array<String>) {
LauncherEnv.initialize(GtkEnvBackend)
Utils.LOGGER.info("Launching Inceptum v" + BuildMetadata.VERSION)
Utils.LOGGER.info("Loading from " + MetaHolder.BASE_PATH)
Log.info("Launching Inceptum v" + BuildMetadata.VERSION)
Log.info("Loading from " + MetaHolder.BASE_PATH)
exitProcess(try {
showGui(args)
} catch (_: Throwable) {

View File

@ -6,6 +6,7 @@ import io.gitlab.jfronny.inceptum.common.MetaHolder
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.menu.MenuBuilder
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Log
import io.gitlab.jfronny.inceptum.gtk.window.AboutWindow
import io.gitlab.jfronny.inceptum.gtk.window.create.NewInstanceWindow
import io.gitlab.jfronny.inceptum.gtk.window.dialog.MicrosoftLoginDialog
@ -155,7 +156,7 @@ object GtkMenubar {
}
}
} catch (e: IOException) {
Utils.LOGGER.error("Could not generate launch menu", e)
Log.error("Could not generate launch menu", e)
}
}
@ -182,7 +183,7 @@ object GtkMenubar {
try {
Steps.reDownload(instance, state)
} catch (e: IOException) {
Utils.LOGGER.error("Could not fetch instance, trying to start anyways", e)
Log.error("Could not fetch instance, trying to start anyways", e)
}
if (state.isCancelled) return@show
state.updateStep("Starting Game")

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.inceptum.gtk
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.util.Log
import java.util.*
private val SCHEDULED: Queue<Runnable> = ArrayDeque()
@ -15,7 +15,7 @@ fun runScheduledTasks() {
try {
r!!.run()
} catch (t: Throwable) {
Utils.LOGGER.error("Could not run scheduled task", t)
Log.error("Could not run scheduled task", t)
}
}
}

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.inceptum.gtk.control.assistant
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.util.Log
import org.gnome.gtk.Application
import org.gnome.gtk.Assistant
import org.gnome.gtk.AssistantPageType
@ -13,7 +14,7 @@ open class KAssistant(app: Application) : Assistant() {
onPrepare { next ->
val page = pages.firstOrNull { it.handle() == next.handle() }
if (page == null) {
Utils.LOGGER.error("Unknown page opened in assistant")
Log.error("Unknown page opened in assistant")
} else {
page.emitOpen()
}

View File

@ -1,6 +1,8 @@
package io.gitlab.jfronny.inceptum.gtk.control.settings
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Log
import org.gnome.adw.HeaderBar
import org.gnome.adw.ViewStack
import org.gnome.adw.ViewSwitcherBar

View File

@ -3,6 +3,7 @@ package io.gitlab.jfronny.inceptum.gtk.menu
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Log
import org.gnome.gio.*
import org.gnome.glib.Variant
import org.gnome.glib.VariantType
@ -51,7 +52,7 @@ class MenuBuilder private constructor(map: ActionMap, menu: Menu, prefix: String
try {
onClick.run()
} catch (e: Throwable) {
Utils.LOGGER.error("Could not execute action", e)
Log.error("Could not execute action", e)
}
}
val menuItem = MenuItem(label, groupName + internalName)

View File

@ -0,0 +1,6 @@
package io.gitlab.jfronny.inceptum.gtk.util
import io.gitlab.jfronny.commons.log.Logger
import io.gitlab.jfronny.inceptum.common.Utils
object Log : Logger by Utils.LOGGER

View File

@ -35,12 +35,12 @@ object Memory {
return if (memTotal.isPresent()) {
parseDecimalMemorySizeToBinary(memTotal.get())
} else {
Utils.LOGGER.error("Could not find total memory")
Log.error("Could not find total memory")
32 * GB
}
}
} catch (e: IOException) {
Utils.LOGGER.error("Could not get total memory", e)
Log.error("Could not get total memory", e)
return 32 * GB
}
}

View File

@ -112,7 +112,7 @@ class MainWindow(app: Application) : ApplicationWindow(app) {
try {
setupDirWatcher()
} catch (e: IOException) {
Utils.LOGGER.error(
Log.error(
"Could not set up watch service, live updates of the instance dir will be unavailable",
e
)
@ -126,7 +126,7 @@ class MainWindow(app: Application) : ApplicationWindow(app) {
try {
if (isw.poll()) generateWindowBody()
} catch (e: IOException) {
Utils.LOGGER.error("Could not run update task", e)
Log.error("Could not run update task", e)
}
GLib.SOURCE_CONTINUE
}
@ -160,7 +160,7 @@ class MainWindow(app: Application) : ApplicationWindow(app) {
stack.queueResize()
stack.queueDraw()
} catch (e: IOException) {
Utils.LOGGER.error("Could not generate window body", e)
Log.error("Could not generate window body", e)
}
}
}

View File

@ -10,6 +10,7 @@ import io.gitlab.jfronny.inceptum.gtk.control.KEntry
import io.gitlab.jfronny.inceptum.gtk.control.assistant.KAssistant
import io.gitlab.jfronny.inceptum.gtk.schedule
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Log
import io.gitlab.jfronny.inceptum.gtk.util.kText
import io.gitlab.jfronny.inceptum.gtk.util.toTypedArray
import io.gitlab.jfronny.inceptum.gtk.window.dialog.ProcessStateWatcherDialog
@ -147,7 +148,7 @@ class NewInstanceWindow(app: Application) : KAssistant(app) {
try {
JFiles.deleteRecursive(MetaHolder.INSTANCE_DIR.resolve(state.name))
} catch (e: IOException) {
Utils.LOGGER.error("Could not delete instance dir", e)
Log.error("Could not delete instance dir", e)
}
return@Thread
}
@ -156,7 +157,7 @@ class NewInstanceWindow(app: Application) : KAssistant(app) {
}
} catch (e: Throwable) {
pState.cancel()
Utils.LOGGER.error("Could not create instance")
Log.error("Could not create instance")
failureMessage = StringFormatter.toString(e)
isFailure = true
} finally {

View File

@ -2,6 +2,7 @@ package io.gitlab.jfronny.inceptum.gtk.window.dialog
import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Log
import io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAccount
import io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAuthAPI
import io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAuthServer
@ -28,7 +29,7 @@ class MicrosoftLoginDialog(
try {
server.start()
} catch (e: Exception) {
Utils.LOGGER.error("Could not start mc login server", e)
Log.error("Could not start mc login server", e)
}
val finalize = Runnable {
server.close()
@ -46,7 +47,7 @@ class MicrosoftLoginDialog(
destroy()
}
else -> Utils.LOGGER.error("Unexpected response type: $responseId")
else -> Log.error("Unexpected response type: $responseId")
}
}
val btn = Button.newWithLabel(I18n["auth.open-browser"])
@ -55,7 +56,7 @@ class MicrosoftLoginDialog(
try {
Utils.openWebBrowser(URI(MicrosoftAuthAPI.MICROSOFT_LOGIN_URL))
} catch (e: URISyntaxException) {
Utils.LOGGER.error("Could not open browser", e)
Log.error("Could not open browser", e)
}
}
onCloseRequest {

View File

@ -6,6 +6,7 @@ import io.gitlab.jfronny.inceptum.common.Utils
import io.gitlab.jfronny.inceptum.gtk.GtkEnvBackend
import io.gitlab.jfronny.inceptum.gtk.schedule
import io.gitlab.jfronny.inceptum.gtk.util.I18n
import io.gitlab.jfronny.inceptum.gtk.util.Log
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState
import org.gnome.glib.GLib
import org.gnome.gtk.*
@ -39,7 +40,7 @@ class ProcessStateWatcherDialog(
}
ResponseType.DELETE_EVENT -> destroy()
else -> Utils.LOGGER.error("Unexpected response type: $responseId")
else -> Log.error("Unexpected response type: $responseId")
}
}
onCloseRequest {
@ -65,7 +66,7 @@ class ProcessStateWatcherDialog(
executor.run()
} catch (e: Throwable) {
state.cancel()
Utils.LOGGER.error(errorMessage, e)
Log.error(errorMessage, e)
GtkEnvBackend.simpleDialog(
parent,
StringFormatter.toString(e),

View File

@ -141,7 +141,7 @@ class GeneralTab(window: InstanceSettingsWindow) : SectionedSettingsTab<Instance
try {
dialog.setFile(File.newForPath(instance.meta.java))
} catch (e: GErrorException) {
Utils.LOGGER.error("Could not set starting point", e)
Log.error("Could not set starting point", e)
}
}
dialog.onResponse { responseId: Int ->