mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
mod logger
This commit is contained in:
parent
e230cdf49a
commit
93fb086658
@ -24,6 +24,7 @@ import de.bixilon.minosoft.modding.loader.LoaderUtil.load
|
|||||||
import de.bixilon.minosoft.modding.loader.error.*
|
import de.bixilon.minosoft.modding.loader.error.*
|
||||||
import de.bixilon.minosoft.modding.loader.mod.MinosoftMod
|
import de.bixilon.minosoft.modding.loader.mod.MinosoftMod
|
||||||
import de.bixilon.minosoft.modding.loader.mod.ModMain
|
import de.bixilon.minosoft.modding.loader.mod.ModMain
|
||||||
|
import de.bixilon.minosoft.modding.loader.mod.logger.ModLogger
|
||||||
import de.bixilon.minosoft.terminal.RunConfiguration
|
import de.bixilon.minosoft.terminal.RunConfiguration
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
import de.bixilon.minosoft.util.logging.LogLevels
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
@ -32,6 +33,7 @@ import java.io.File
|
|||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.util.jar.JarEntry
|
import java.util.jar.JarEntry
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
|
import kotlin.reflect.jvm.javaField
|
||||||
|
|
||||||
|
|
||||||
object ModLoader {
|
object ModLoader {
|
||||||
@ -123,7 +125,8 @@ object ModLoader {
|
|||||||
if (main !is ModMain) {
|
if (main !is ModMain) {
|
||||||
throw NoModMainError(mainClass)
|
throw NoModMainError(mainClass)
|
||||||
}
|
}
|
||||||
main.assets = assetsManager!!
|
ASSETS_MANAGER_FIELD[main] = assetsManager!!
|
||||||
|
LOGGER_FIELD[main] = ModLogger(manifest.name)
|
||||||
this.main = main
|
this.main = main
|
||||||
main.init()
|
main.init()
|
||||||
}
|
}
|
||||||
@ -288,4 +291,8 @@ object ModLoader {
|
|||||||
}
|
}
|
||||||
throw IllegalStateException("$phase has not started yet!")
|
throw IllegalStateException("$phase has not started yet!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val ASSETS_MANAGER_FIELD = ModMain::assets.javaField!!.apply { isAccessible = true }
|
||||||
|
private val LOGGER_FIELD = ModMain::logger.javaField!!.apply { isAccessible = true }
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@ package de.bixilon.minosoft.modding.loader.mod
|
|||||||
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
||||||
import de.bixilon.minosoft.assets.AssetsManager
|
import de.bixilon.minosoft.assets.AssetsManager
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable
|
import de.bixilon.minosoft.gui.rendering.gui.hud.Initializable
|
||||||
|
import de.bixilon.minosoft.modding.loader.mod.logger.ModLogger
|
||||||
|
|
||||||
abstract class ModMain : Initializable {
|
abstract class ModMain : Initializable {
|
||||||
var assets: AssetsManager = unsafeNull()
|
val assets: AssetsManager = unsafeNull()
|
||||||
|
val logger: ModLogger = unsafeNull()
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.modding.loader.mod.logger
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
|
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||||
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
|
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||||
|
|
||||||
|
class ModLogger(name: String) {
|
||||||
|
private val prefix = TextComponent("[$name] ").color(ChatColors.BLUE)
|
||||||
|
|
||||||
|
fun fatal(message: () -> Any?) {
|
||||||
|
Log.log(LogMessageType.MODS, LogLevels.FATAL, prefix, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun warn(message: () -> Any?) {
|
||||||
|
Log.log(LogMessageType.MODS, LogLevels.WARN, prefix, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun info(message: () -> Any?) {
|
||||||
|
Log.log(LogMessageType.MODS, LogLevels.INFO, prefix, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun verbose(message: () -> Any?) {
|
||||||
|
Log.log(LogMessageType.MODS, LogLevels.VERBOSE, prefix, message)
|
||||||
|
}
|
||||||
|
}
|
@ -115,7 +115,7 @@ object Log {
|
|||||||
@DoNotCall
|
@DoNotCall
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun log(type: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, message: Any, vararg formatting: Any) {
|
fun log(type: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, message: Any?, vararg formatting: Any) {
|
||||||
if (skipLogging(type, level)) {
|
if (skipLogging(type, level)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ object Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun log(type: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, messageBuilder: () -> Any) {
|
fun log(type: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, messageBuilder: () -> Any?) {
|
||||||
if (skipLogging(type, level)) {
|
if (skipLogging(type, level)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -159,12 +159,12 @@ object Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun log(type: LogMessageType, level: LogLevels, messageBuilder: () -> Any) {
|
fun log(type: LogMessageType, level: LogLevels, messageBuilder: () -> Any?) {
|
||||||
log(type, level = level, additionalPrefix = null, messageBuilder = messageBuilder)
|
log(type, level = level, additionalPrefix = null, messageBuilder = messageBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun log(type: LogMessageType, messageBuilder: () -> Any) {
|
fun log(type: LogMessageType, messageBuilder: () -> Any?) {
|
||||||
log(type, additionalPrefix = null, messageBuilder = messageBuilder)
|
log(type, additionalPrefix = null, messageBuilder = messageBuilder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,14 @@ enum class LogMessageType(
|
|||||||
),
|
),
|
||||||
|
|
||||||
PROFILES(ChatColors.AQUA),
|
PROFILES(ChatColors.AQUA),
|
||||||
|
|
||||||
|
MODS(
|
||||||
|
ChatColors.WHITE, mapOf(
|
||||||
|
LogLevels.FATAL to ChatColors.DARK_RED,
|
||||||
|
LogLevels.WARN to ChatColors.RED,
|
||||||
|
LogLevels.VERBOSE to ChatColors.YELLOW,
|
||||||
|
)
|
||||||
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
companion object : ValuesEnum<LogMessageType> {
|
companion object : ValuesEnum<LogMessageType> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user