Skip to content

Instantly share code, notes, and snippets.

@sylv256
Forked from FiniteReality/log4j2.xml
Last active October 12, 2024 03:30
Show Gist options
  • Save sylv256/2b9c6734b56cadee8b669ad18006935d to your computer and use it in GitHub Desktop.
Save sylv256/2b9c6734b56cadee8b669ad18006935d to your computer and use it in GitHub Desktop.
Fabrified NeoForge Log4J Config
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<!-- Standard output -->
<TerminalConsole name="SysOut">
<Select>
<!-- If we're running through the launcher, format messages using XML -->
<SystemPropertyArbiter propertyName="minecraft.launcher.brand" propertyValue="minecraft-launcher">
<LegacyXMLLayout/>
</SystemPropertyArbiter>
<!-- Otherwise, use the vanilla format assuming it's a console -->
<DefaultArbiter>
<!-- Support ANSI escape sequences if we're running interactively -->
<PatternLayout pattern="%style{[%d{HH:mm:ss}]}{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}">
<Replace regex="\r?\n(?!\Z)" replacement="${sys:line.separator}" />
</PatternLayout>
</DefaultArbiter>
</Select>
</TerminalConsole>
<!-- Interactive server console -->
<Queue name="ServerGuiConsole">
<!-- This is the same format used by the standard vanilla console -->
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg{nolookups}%n"/>
</Queue>
<!-- File logging -->
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
<!-- Strip any ANSI escape sequences if possible, and use a derivative of the vanilla format which includes the logger name -->
<!-- TODO: it would be nice to include the mod id here too; this would likely need a custom context lookup though and may not work -->
<PatternLayout disableAnsi="true" pattern="[%d{HH:mm:ss}] [%t/%level] [%c]: %msg{nolookups}%n"/>
<Policies>
<!-- Only roll over per launch of the game/server -->
<!-- This is for ease of bug reports: users only have to upload logs/latest.log -->
<OnStartupTriggeringPolicy/>
</Policies>
<!-- Only keep the past 10 logfiles to prevent logfile spam -->
<DefaultRolloverStrategy max="10" fileIndex="min"/>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<!-- Minecraft uses isDebugEnabled() in some places to add additional debug logic, which we typically don't want enabled. -->
<Logger name="com.mojang" level="INFO"/>
<Logger name="net.minecraft" level="INFO"/>
<!-- Hide class transform logging -->
<Logger name="cpw.mods.modlauncher.ClassTransformer" level="INFO"/>
<!-- Netty has extra requirements for modular environments which we can't yet satisfy: https://github.com/netty/netty/issues/7838 -->
<!-- This causes errors we can't hide, as netty is not on the module boot path: https://github.com/neoforged/FancyModLoader/pull/61 -->
<Logger name="io.netty.util.internal.PlatformDependent0">
<Filters>
<RegexFilter regex="^direct buffer constructor: unavailable$" onMatch="DENY" onMismatch="NEUTRAL" />
<RegexFilter regex="^jdk\.internal\.misc\.Unsafe\.allocateUninitializedArray\(int\): unavailable$" onMatch="DENY" onMismatch="NEUTRAL" />
</Filters>
</Logger>
<!-- Default logging inherited by all loggers. Users can specify loglevels for specific loggers in a composite configuration. -->
<Root level="INFO">
<Filters>
<!-- Hide network packet logging a la vanilla -->
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
<!-- Also hide our more advanced logging -->
<MarkerFilter marker="CLASSLOADING" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="LAUNCHPLUGIN" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="CLASSDUMP" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="AXFORM" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="EVENTBUS" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="DISTXFORM" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="SCAN" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="REGISTRIES" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="REGISTRYDUMP" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="SPLASH" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="RESOURCE-CACHE" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
<AppenderRef ref="SysOut">
<!-- Only send info and above to stdout -->
<ThresholdFilter level="INFO"/>
</AppenderRef>
<!-- File logging can get everything, including debug messages, to make uploading logs easier. -->
<AppenderRef ref="File"/>
<!-- The server GUI console is meant to mirror stdout -->
<AppenderRef ref="ServerGuiConsole">
<ThresholdFilter level="INFO"/>
</AppenderRef>
</Root>
</Loggers>
</Configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment