Skip to content

Commit 182b126

Browse files
authored
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. GitHub: #83
1 parent e7a43ed commit 182b126

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

standalone/build.gradle.kts

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ dependencies {
3737
// Same as above but we do not want to expose them to our downstream so we can eventually remove them
3838
implementation("org.apache.logging.log4j:log4j-api:2.23.1")
3939
implementation("org.apache.logging.log4j:log4j-core:2.23.1")
40-
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.23.1")
40+
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1")
4141
implementation("com.google.code.gson:gson:2.11.0")
4242
implementation("commons-codec:commons-codec:1.17.1")
4343
implementation("org.apache.httpcomponents:httpclient:4.5.14")
44+
// Pretty colors in Console logs
45+
implementation("net.minecrell:terminalconsoleappender:1.3.0")
4446
}
4547

4648
tasks.processResources {

standalone/example/src/main/kotlin/gg/essential/example/main.kt

+5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import gg.essential.universal.standalone.runUniversalCraft
1111
import gg.essential.universal.UResolution
1212
import gg.essential.universal.UScreen
1313
import kotlinx.coroutines.launch
14+
import org.slf4j.LoggerFactory
1415
import java.awt.Color
1516

17+
private val LOGGER = LoggerFactory.getLogger("Example")
18+
1619
fun main() = runUniversalCraft("Example", 1000, 600) { window ->
1720
val extraFontsLoaded = mutableStateOf(false)
1821
launch {
@@ -23,6 +26,8 @@ fun main() = runUniversalCraft("Example", 1000, 600) { window ->
2326
UMinecraft.guiScale = 2 * (UResolution.viewportWidth / UResolution.windowWidth)
2427
UScreen.displayScreen(LayoutDslScreen { exampleScreen(extraFontsLoaded) })
2528

29+
LOGGER.info("All ready!")
30+
2631
window.renderScreenUntilClosed()
2732
}
2833

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<TerminalConsole name="Console">
5+
<PatternLayout pattern="%style{[%d{HH:mm:ss.SSS}]}{blue} %highlight{[%t/%level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=green, TRACE=blue} %style{(%logger{1})}{cyan} %highlight{%msg%n}{FATAL=red, ERROR=red, WARN=normal, INFO=normal, DEBUG=normal, TRACE=normal}" disableAnsi="${tca:disableAnsi}"/>
6+
</TerminalConsole>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="all">
10+
<AppenderRef ref="Console" level="${sys:log4j2.level:-info}"/>
11+
</Root>
12+
</Loggers>
13+
</Configuration>

0 commit comments

Comments
 (0)