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?