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 detection
This commit is contained in:
modmuss50
2020-04-04 14:18:40 +01:00
committed by GitHub
parent bb68465a8d
commit dff10a5d79
3 changed files with 89 additions and 0 deletions

View File

@@ -26,8 +26,11 @@ package net.fabricmc.loom.providers;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -49,6 +52,7 @@ public class LaunchProvider extends DependencyProvider {
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws IOException {
final LaunchConfig launchConfig = new LaunchConfig()
.property("fabric.development", "true")
.property("log4j.configurationFile", getLog4jConfigFile().getAbsolutePath())
.property("client", "java.library.path", 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", 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);
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

View File

@@ -56,4 +56,5 @@ public class Constants {
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 TERMINAL_CONSOLE_APPENDER_VERSION = "1.2.0";
}