From 9ea7f0ff2a3116f64c4e0d1048664a80e770bbd2 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Wed, 14 Aug 2024 13:39:31 +0200 Subject: [PATCH] Standalone: Fix slf4j logging and add default log4j config We use version 2 of slf4j, so we need to include the log4j adapter which was built for version 2, not the one for version 1. With that, logging works, but it's using log4j's ugly default format and only emits WARN or above. To improve the out-of-the-box behavior for Standalone UC, we add a default log4j config file; applications which require further customization can override it via one of the many way which log4j provides. --- standalone/build.gradle.kts | 4 +++- .../src/main/kotlin/gg/essential/example/main.kt | 5 +++++ standalone/src/main/resources/log4j2.xml | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 standalone/src/main/resources/log4j2.xml diff --git a/standalone/build.gradle.kts b/standalone/build.gradle.kts index b9daf56..0ed405a 100644 --- a/standalone/build.gradle.kts +++ b/standalone/build.gradle.kts @@ -37,10 +37,12 @@ dependencies { // Same as above but we do not want to expose them to our downstream so we can eventually remove them implementation("org.apache.logging.log4j:log4j-api:2.23.1") implementation("org.apache.logging.log4j:log4j-core:2.23.1") - implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.23.1") + implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1") implementation("com.google.code.gson:gson:2.11.0") implementation("commons-codec:commons-codec:1.17.1") implementation("org.apache.httpcomponents:httpclient:4.5.14") + // Pretty colors in Console logs + implementation("net.minecrell:terminalconsoleappender:1.3.0") } tasks.processResources { diff --git a/standalone/example/src/main/kotlin/gg/essential/example/main.kt b/standalone/example/src/main/kotlin/gg/essential/example/main.kt index be4082e..2c0d2e7 100644 --- a/standalone/example/src/main/kotlin/gg/essential/example/main.kt +++ b/standalone/example/src/main/kotlin/gg/essential/example/main.kt @@ -11,8 +11,11 @@ import gg.essential.universal.standalone.runUniversalCraft import gg.essential.universal.UResolution import gg.essential.universal.UScreen import kotlinx.coroutines.launch +import org.slf4j.LoggerFactory import java.awt.Color +private val LOGGER = LoggerFactory.getLogger("Example") + fun main() = runUniversalCraft("Example", 1000, 600) { window -> val extraFontsLoaded = mutableStateOf(false) launch { @@ -23,6 +26,8 @@ fun main() = runUniversalCraft("Example", 1000, 600) { window -> UMinecraft.guiScale = 2 * (UResolution.viewportWidth / UResolution.windowWidth) UScreen.displayScreen(LayoutDslScreen { exampleScreen(extraFontsLoaded) }) + LOGGER.info("All ready!") + window.renderScreenUntilClosed() } diff --git a/standalone/src/main/resources/log4j2.xml b/standalone/src/main/resources/log4j2.xml new file mode 100644 index 0000000..c45ed07 --- /dev/null +++ b/standalone/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file