Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm aware that Forge already uses Log4J for logging and exposes a preconfigured logger for each mod though FMLPreInitializationEvent::getModLog() however, for my purposes, this is insufficient. I need to be able to actually set the configuration of the logger as I need to have two separate loggers, one as a debug logger that can be configured to only log error level or above on the actually server while being able to be set to trace level on a developer machine. The other would simply be for maintaining a chat log with some custom information.

This would be fairly trivial if I could configure the loggers myself, however, there doesn't seem to be an exposed log4j configuration in a Forge setup, and if I try to define my own and pass it to Log4J programmatically, FML overrides.

 

For instance, here is a log4j configuration:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="debug-file" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="C:\path\to\debug.log"/>
        <param name="append" value="true"/>
        <param name="encoding" value="UTF-8"/>
        <param name="MaxFileSize" value="500MB"/>

        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601} %p | %m%n"/>
        </layout>
    </appender>

    <logger name="logger.name" additivity="false">
        <level value="all"/>
        <appender-ref ref="debug-file"/>
    </logger>
</log4j:configuration>

This is a perfectly fine Log4J configuration for a logger. The problem comes below:

ConfigurationSource source = new ConfigurationSource(new FileInputStream(new File("C:\path\to\config.xml")));
LoggerContext logSource = Configurator.initialize(null, source);

Logger logger = logSource.getLogger("logger.name");

To pass a configuration file into Log4J programmatically you'd do those first two lines, and then you should be able to just get the logger from the resulting LoggerContext. Unfortunately, what I end up getting is the preconfigured pile of loggers from Forge.

 

So, is there any way that I can define my loggers with a custom config, or do I just need to give up and configure them entirely programmatically?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.