Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone: Fix slf4j logging and add default log4j config #83

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion standalone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}

Expand Down
13 changes: 13 additions & 0 deletions standalone/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<TerminalConsole name="Console">
<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}"/>
</TerminalConsole>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="Console" level="${sys:log4j2.level:-info}"/>
</Root>
</Loggers>
</Configuration>