Logging

Whenever you develop a program you’ll eventually bump into some bugs. To find them you’re going to need proper logging. Zircon comes with its own logger facade and with some minimal setup we can take advantage of this.

Zircon uses Logback behind the scenes for logging on the JVM platform. What’s very useful is that Zircon has proper and insightful debug statements throughout the codebase which you can enable by editing the logger config in logback.xml. The most important part is that you can enable only those parts which you are interested in so you won’t get an undecypherable mess. The config looks like this:

This file goes to /src/main/resources/logback.xml, so if you don’t have it you have to create it.

<configuration>

    <!-- We only print to the console (stdout) by default using the following format -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Logging is set to info by default for our console logger -->
    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>

    <!-- You can either set logging level for whole packages -->
    <logger name="org.hexworks.zircon" level="warn"/>
    <logger name="org.hexworks.cobalt" level="warn"/>

    <!-- Or individual classes -->
    <logger name="org.hexworks.zircon.api.component.Button" level="debug"/>
    
</configuration>

We’re gradually adding proper debug statements throughout all of the api classes so if you have trouble with any of them just enable debug logging and you’ll see what happens, no additional setup needed. It looks like this:

19:58:14.149 [main] DEBUG o.h.zircon.api.component.Button - Button (id=efe8, enabled=true) was rendered.
19:58:14.153 [main] DEBUG o.h.zircon.api.component.Button - Applying color theme: DefaultColorTheme(primaryForegroundColor=DefaultTileColor(red=248, green=237, blue=209, alpha=255), secondaryForegroundColor=DefaultTileColor(red=197, green=207, blue=198, alpha=255), primaryBackgroundColor=DefaultTileColor(red=157, green=157, blue=147, alpha=255), secondaryBackgroundColor=DefaultTileColor(red=71, green=72, blue=67, alpha=255), accentColor=DefaultTileColor(red=184, green=106, blue=106, alpha=255)) to Button (id=e60a, enabled=true).
19:58:14.154 [main] DEBUG o.h.zircon.api.component.Button - Button (id=e60a, enabled=true) was rendered.
19:58:15.540 [LWJGL Application] DEBUG o.h.zircon.api.component.Button - Button (id=e60a, enabled=true) was mouse entered.
19:58:15.540 [LWJGL Application] DEBUG o.h.zircon.api.component.Button - Button (id=e60a, enabled=true) was rendered.

Do you have questions? Ask us on our Discord Server.

If you like what we do and want to support us consider becoming a Patron.