Add log4jConfigs to Loom extension (#356)

Allows mod build scripts to specify custom Log4j config files that will
be combined together when running Minecraft in the dev-env. For example:

    loom {
        log4jConfigs.from "MyCustomConfig.xml"
    }

See: https://logging.apache.org/log4j/2.x/manual/configuration.html#CompositeConfiguration
dev/0.11
Shadowfacts 2021-02-26 16:19:26 -05:00 committed by GitHub
parent 57c9a8f320
commit 4540b3af33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -66,6 +66,7 @@ public class LoomGradleExtension {
public boolean shareCaches = false;
private final ConfigurableFileCollection unmappedMods;
private final ConfigurableFileCollection log4jConfigs;
final List<LoomDecompiler> decompilers = new ArrayList<>();
private final List<JarProcessor> jarProcessors = new ArrayList<>();
@ -117,6 +118,7 @@ public class LoomGradleExtension {
this.unmappedMods = project.files();
this.runConfigs = project.container(RunConfigSettings.class,
baseName -> new RunConfigSettings(project, baseName));
this.log4jConfigs = project.files(getDefaultLog4jConfigFile());
}
/**
@ -348,6 +350,14 @@ public class LoomGradleExtension {
return decompilers;
}
public File getDefaultLog4jConfigFile() {
return new File(getProjectPersistentCache(), "log4j.xml");
}
public ConfigurableFileCollection getLog4jConfigs() {
return log4jConfigs;
}
@ApiStatus.Experimental
public void runs(Action<NamedDomainObjectContainer<RunConfigSettings>> action) {
action.execute(runConfigs);

View File

@ -59,7 +59,7 @@ public class LaunchProvider extends DependencyProvider {
final LaunchConfig launchConfig = new LaunchConfig()
.property("fabric.development", "true")
.property("fabric.remapClasspathFile", getRemapClasspathFile().getAbsolutePath())
.property("log4j.configurationFile", getLog4jConfigFile().getAbsolutePath())
.property("log4j.configurationFile", getAllLog4JConfigFiles())
.property("client", "java.library.path", getExtension().getNativesDirectory().getAbsolutePath())
.property("client", "org.lwjgl.librarypath", getExtension().getNativesDirectory().getAbsolutePath())
@ -87,7 +87,13 @@ public class LaunchProvider extends DependencyProvider {
}
private File getLog4jConfigFile() {
return new File(getExtension().getDevLauncherConfig().getParentFile(), "log4j.xml");
return getExtension().getDefaultLog4jConfigFile();
}
private String getAllLog4JConfigFiles() {
return getExtension().getLog4jConfigs().getFiles().stream()
.map(File::getAbsolutePath)
.collect(Collectors.joining(","));
}
private File getRemapClasspathFile() {