mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 15:27:50 +07:00
Add simple logging solution (#6952)
* Add simple logging solution * Fix Android compilation For some reason I stashed this and didn't unstash. * Add better logging explanation
This commit is contained in:
@ -3,6 +3,7 @@ package com.unciv.app.desktop
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.UncivGameParameters
|
||||
import com.unciv.utils.Log
|
||||
import com.unciv.logic.GameStarter
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.map.MapParameters
|
||||
@ -22,6 +23,7 @@ internal object ConsoleLauncher {
|
||||
@ExperimentalTime
|
||||
@JvmStatic
|
||||
fun main(arg: Array<String>) {
|
||||
Log.backend = DesktopLogBackend()
|
||||
|
||||
val version = "0.1"
|
||||
val consoleParameters = UncivGameParameters(
|
||||
|
@ -9,8 +9,9 @@ import com.badlogic.gdx.graphics.glutils.HdpiMode
|
||||
import com.sun.jna.Native
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.UncivGameParameters
|
||||
import com.unciv.utils.Log
|
||||
import com.unciv.utils.debug
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
import com.unciv.ui.utils.Fonts
|
||||
import java.util.*
|
||||
import kotlin.concurrent.timer
|
||||
@ -20,6 +21,7 @@ internal object DesktopLauncher {
|
||||
|
||||
@JvmStatic
|
||||
fun main(arg: Array<String>) {
|
||||
Log.backend = DesktopLogBackend()
|
||||
// Solves a rendering problem in specific GPUs and drivers.
|
||||
// For more info see https://github.com/yairm210/Unciv/pull/3202 and https://github.com/LWJGL/lwjgl/issues/119
|
||||
System.setProperty("org.lwjgl.opengl.Display.allowSoftwareOpenGL", "true")
|
||||
@ -85,7 +87,7 @@ internal object DesktopLauncher {
|
||||
}
|
||||
} catch (ex: Throwable) {
|
||||
// This needs to be a Throwable because if we can't find the discord_rpc library, we'll get a UnsatisfiedLinkError, which is NOT an exception.
|
||||
println("Could not initialize Discord")
|
||||
debug("Could not initialize Discord")
|
||||
}
|
||||
}
|
||||
|
||||
|
16
desktop/src/com/unciv/app/desktop/DesktopLogBackend.kt
Normal file
16
desktop/src/com/unciv/app/desktop/DesktopLogBackend.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package com.unciv.app.desktop
|
||||
|
||||
import com.unciv.utils.DefaultLogBackend
|
||||
import java.lang.management.ManagementFactory
|
||||
|
||||
class DesktopLogBackend : DefaultLogBackend() {
|
||||
|
||||
// -ea (enable assertions) or kotlin debugging property as marker for a debug run.
|
||||
// Can easily be added to IntelliJ/Android Studio launch configuration template for all launches.
|
||||
private val release = !ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-ea")
|
||||
&& System.getProperty("kotlinx.coroutines.debug") == null
|
||||
|
||||
override fun isRelease(): Boolean {
|
||||
return release
|
||||
}
|
||||
}
|
@ -3,15 +3,17 @@ package com.unciv.app.desktop
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.utils.Log
|
||||
import com.unciv.utils.debug
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Entry point: _ImagePacker.[packImages] ()_
|
||||
*
|
||||
*
|
||||
* Re-packs our texture assets into atlas + png File pairs, which will be loaded by the game.
|
||||
* With the exception of the ExtraImages folder and the Font system these are the only
|
||||
* graphics used (The source Image folders are unused at run time except here).
|
||||
*
|
||||
*
|
||||
* [TexturePacker] documentation is [here](https://github.com/libgdx/libgdx/wiki/Texture-packer)
|
||||
*/
|
||||
internal object ImagePacker {
|
||||
@ -68,14 +70,14 @@ internal object ImagePacker {
|
||||
try {
|
||||
packImagesPerMod(mod.path, mod.path, defaultSettings)
|
||||
} catch (ex: Throwable) {
|
||||
println("Exception in ImagePacker: ${ex.message}")
|
||||
Log.error("Exception in ImagePacker: %s", ex.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val texturePackingTime = System.currentTimeMillis() - startTime
|
||||
println("Packing textures - " + texturePackingTime + "ms")
|
||||
debug("Packing textures - %sms", texturePackingTime)
|
||||
}
|
||||
|
||||
// Scan multiple image folders and generate an atlas for each - if outdated
|
||||
|
@ -7,6 +7,7 @@ import com.sun.jna.Pointer
|
||||
import com.sun.jna.platform.win32.User32
|
||||
import com.sun.jna.platform.win32.WinNT
|
||||
import com.sun.jna.platform.win32.WinUser
|
||||
import com.unciv.utils.Log
|
||||
import org.lwjgl.glfw.GLFWNativeWin32
|
||||
|
||||
class MultiplayerTurnNotifierDesktop: Lwjgl3WindowAdapter() {
|
||||
@ -18,7 +19,7 @@ class MultiplayerTurnNotifierDesktop: Lwjgl3WindowAdapter() {
|
||||
null
|
||||
}
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
println("Error while initializing turn notifier: " + e.message)
|
||||
Log.error("Error while initializing turn notifier", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
@ -58,7 +59,7 @@ class MultiplayerTurnNotifierDesktop: Lwjgl3WindowAdapter() {
|
||||
user32.FlashWindowEx(flashwinfo)
|
||||
} catch (e: Throwable) {
|
||||
/** try to ignore even if we get an [Error], just log it */
|
||||
println("Error while notifying the user of their turn: " + e.message)
|
||||
Log.error("Error while notifying the user of their turn", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user