Use a custom dev time log4j config. Enables color output and improves overall logging. (#186)
* Use a custom dev time log4j config. Enables color output and improves overall logging. Color output is not enabled by default for eclipse users * Use the run config to force enable ansi colors * Improve IDE detectiondev/0.11
parent
bb68465a8d
commit
dff10a5d79
|
@ -26,8 +26,11 @@ package net.fabricmc.loom.providers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -49,6 +52,7 @@ public class LaunchProvider extends DependencyProvider {
|
||||||
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws IOException {
|
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws IOException {
|
||||||
final LaunchConfig launchConfig = new LaunchConfig()
|
final LaunchConfig launchConfig = new LaunchConfig()
|
||||||
.property("fabric.development", "true")
|
.property("fabric.development", "true")
|
||||||
|
.property("log4j.configurationFile", getLog4jConfigFile().getAbsolutePath())
|
||||||
|
|
||||||
.property("client", "java.library.path", getExtension().getNativesDirectory().getAbsolutePath())
|
.property("client", "java.library.path", getExtension().getNativesDirectory().getAbsolutePath())
|
||||||
.property("client", "org.lwjgl.librarypath", getExtension().getNativesDirectory().getAbsolutePath())
|
.property("client", "org.lwjgl.librarypath", getExtension().getNativesDirectory().getAbsolutePath())
|
||||||
|
@ -58,9 +62,31 @@ public class LaunchProvider extends DependencyProvider {
|
||||||
.argument("client", "--assetsDir")
|
.argument("client", "--assetsDir")
|
||||||
.argument("client", new File(getExtension().getUserCache(), "assets").getAbsolutePath());
|
.argument("client", new File(getExtension().getUserCache(), "assets").getAbsolutePath());
|
||||||
|
|
||||||
|
//Enable ansi by default for idea and vscode
|
||||||
|
if (new File(getProject().getRootDir(), ".vscode").exists()
|
||||||
|
|| new File(getProject().getRootDir(), ".idea").exists()
|
||||||
|
|| (Arrays.stream(getProject().getRootDir().listFiles()).anyMatch(file -> file.getName().endsWith(".iws")))) {
|
||||||
|
launchConfig.property("fabric.log.disableAnsi", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
writeLog4jConfig();
|
||||||
FileUtils.writeStringToFile(getExtension().getDevLauncherConfig(), launchConfig.asString(), StandardCharsets.UTF_8);
|
FileUtils.writeStringToFile(getExtension().getDevLauncherConfig(), launchConfig.asString(), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
addDependency("net.fabricmc:dev-launch-injector:" + Constants.DEV_LAUNCH_INJECTOR_VERSION, "runtimeOnly");
|
addDependency("net.fabricmc:dev-launch-injector:" + Constants.DEV_LAUNCH_INJECTOR_VERSION, "runtimeOnly");
|
||||||
|
addDependency("net.minecrell:terminalconsoleappender:" + Constants.TERMINAL_CONSOLE_APPENDER_VERSION, "runtimeOnly");
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getLog4jConfigFile() {
|
||||||
|
return new File(getExtension().getDevLauncherConfig().getParentFile(), "log4j.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeLog4jConfig() {
|
||||||
|
try (InputStream is = LaunchProvider.class.getClassLoader().getResourceAsStream("log4j2.fabric.xml")) {
|
||||||
|
Files.deleteIfExists(getLog4jConfigFile().toPath());
|
||||||
|
Files.copy(is, getLog4jConfigFile().toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to generate log4j config", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -56,4 +56,5 @@ public class Constants {
|
||||||
|
|
||||||
public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.3.0.4";
|
public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.3.0.4";
|
||||||
public static final String DEV_LAUNCH_INJECTOR_VERSION = "0.2.0+build.6";
|
public static final String DEV_LAUNCH_INJECTOR_VERSION = "0.2.0+build.6";
|
||||||
|
public static final String TERMINAL_CONSOLE_APPENDER_VERSION = "1.2.0";
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN" packages="com.mojang.util,net.minecrell.terminalconsole.util">
|
||||||
|
<Appenders>
|
||||||
|
|
||||||
|
<!-- System out -->
|
||||||
|
<Console name="SysOut" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout>
|
||||||
|
<LoggerNamePatternSelector defaultPattern="%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}" disableAnsi="${sys:fabric.log.disableAnsi:-true}">
|
||||||
|
<!-- Dont show the logger name for minecraft classes-->
|
||||||
|
<PatternMatch key="net.minecraft.,com.mojang." pattern="%style{[%d{HH:mm:ss}]}{blue} %highlight{[%t/%level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=green, TRACE=blue} %style{(Minecraft)}{cyan} %highlight{%msg%n}{FATAL=red, ERROR=red, WARN=normal, INFO=normal, DEBUG=normal, TRACE=normal}" disableAnsi="${sys:fabric.log.disableAnsi:-true}"/>
|
||||||
|
</LoggerNamePatternSelector>
|
||||||
|
</PatternLayout>
|
||||||
|
</Console>
|
||||||
|
|
||||||
|
<!-- Vanilla server gui -->
|
||||||
|
<Queue name="ServerGuiConsole" ignoreExceptions="true">
|
||||||
|
<PatternLayout>
|
||||||
|
<LoggerNamePatternSelector defaultPattern="[%d{HH:mm:ss} %level] (%logger{1}) %msg%n">
|
||||||
|
<!-- Dont show the logger name for minecraft classes-->
|
||||||
|
<PatternMatch key="net.minecraft.,com.mojang." pattern="[%d{HH:mm:ss} %level] %msg%n"/>
|
||||||
|
</LoggerNamePatternSelector>
|
||||||
|
</PatternLayout>
|
||||||
|
</Queue>
|
||||||
|
|
||||||
|
<!-- latest.log same as vanilla -->
|
||||||
|
<RollingRandomAccessFile name="LatestFile" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
|
||||||
|
<PatternLayout>
|
||||||
|
<LoggerNamePatternSelector defaultPattern="[%d{HH:mm:ss}] [%t/%level] (%logger{1}) %msg%n">
|
||||||
|
<!-- Dont show the logger name for minecraft classes-->
|
||||||
|
<PatternMatch key="net.minecraft.,com.mojang." pattern="[%d{HH:mm:ss}] [%t/%level] (Minecraft) %msg%n"/>
|
||||||
|
</LoggerNamePatternSelector>
|
||||||
|
</PatternLayout>
|
||||||
|
<Policies>
|
||||||
|
<TimeBasedTriggeringPolicy />
|
||||||
|
<OnStartupTriggeringPolicy />
|
||||||
|
</Policies>
|
||||||
|
</RollingRandomAccessFile>
|
||||||
|
|
||||||
|
<!-- Debug log file -->
|
||||||
|
<RollingRandomAccessFile name="DebugFile" fileName="logs/debug.log" filePattern="logs/debug-%i.log.gz">
|
||||||
|
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level] (%logger) %msg%n" />
|
||||||
|
|
||||||
|
<!-- Keep 5 files max -->
|
||||||
|
<DefaultRolloverStrategy max="5" fileIndex="min"/>
|
||||||
|
|
||||||
|
<Policies>
|
||||||
|
<SizeBasedTriggeringPolicy size="500MB"/>
|
||||||
|
<OnStartupTriggeringPolicy />
|
||||||
|
</Policies>
|
||||||
|
|
||||||
|
</RollingRandomAccessFile>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger level="${sys:fabric.log.level:-info}" name="net.minecraft"/>
|
||||||
|
<Root level="all">
|
||||||
|
<AppenderRef ref="DebugFile" level="${sys:fabric.log.debug.level:-debug}"/>
|
||||||
|
<AppenderRef ref="SysOut" level="${sys:fabric.log.level:-info}"/>
|
||||||
|
<AppenderRef ref="LatestFile" level="${sys:fabric.log.level:-info}"/>
|
||||||
|
<AppenderRef ref="ServerGuiConsole" level="${sys:fabric.log.level:-info}"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
Loading…
Reference in New Issue