Fix up logging and log4j configuration (#4802)

This commit is contained in:
mezz authored and GitHub committed 2018-03-17 18:41:16 -07:00
1 parent 5ace86da12
commit ae654edfc2
29 files changed
+308 -206

No files matched your search

@@ -51,6 +51,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
@@ -60,6 +61,8 @@ import javax.annotation.Nullable;
*/
public final class FMLContainer extends DummyModContainer implements WorldAccessContainer
{
private static final Logger modTrackerLogger = LogManager.getLogger("FML.ModTracker");
public FMLContainer()
{
super(new ModMetadata());
@@ -190,12 +193,12 @@ public final class FMLContainer extends DummyModContainer implements WorldAccess
ModContainer container = Loader.instance().getIndexedModList().get(modId);
if (container == null)
{
LogManager.getLogger("fml.ModTracker").error("This world was saved with mod {} which appears to be missing, things may not work well", modId);
modTrackerLogger.error("This world was saved with mod {} which appears to be missing, things may not work well", modId);
continue;
}
if (!modVersion.equals(container.getVersion()))
{
LogManager.getLogger("fml.ModTracker").info("This world was saved with mod {} version {} and it is now at version {}, things may not work well", modId, modVersion, container.getVersion());
modTrackerLogger.info("This world was saved with mod {} version {} and it is now at version {}, things may not work well", modId, modVersion, container.getVersion());
}
}
}
@@ -19,37 +19,21 @@
package net.minecraftforge.fml.common;
import java.util.Locale;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
import net.minecraftforge.fml.relauncher.FMLRelaunchLog;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
/**
* FMLs logging class. <b>Internal use only, NOT FOR MOD LOGGING!</b> Mods use your own log, see {@link FMLPreInitializationEvent#getModLog()}.
* TODO 1.13 remove all the deprecated methods
*/
public class FMLLog
{
public static final Logger log;
static {
log = LogManager.getLogger("FML");
// Default side to client for test harness purposes
Side side = FMLLaunchHandler.side();
if (side == null) side = Side.CLIENT;
ThreadContext.put("side", side.name().toLowerCase(Locale.ENGLISH));
log.debug("Injecting tracing printstreams for STDOUT/STDERR.");
System.setOut(new TracingPrintStream(LogManager.getLogger("STDOUT"), System.out));
System.setErr(new TracingPrintStream(LogManager.getLogger("STDERR"), System.err));
}
public static final Logger log = LogManager.getLogger("FML");
public static void bigWarning(String format, Object... data)
{
@@ -58,8 +58,6 @@ import net.minecraftforge.fml.relauncher.Side;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -106,8 +104,6 @@ public class FMLModContainer implements ModContainer
private URL updateJSONUrl;
private int classVersion;
private final Logger modLog;
public FMLModContainer(String className, ModCandidate container, Map<String, Object> modDescriptor)
{
this.className = className;
@@ -129,8 +125,6 @@ public class FMLModContainer implements ModContainer
FMLLog.log.trace("Using custom language adapter {} for {} (modid: {})", languageAdapterType, this.className, getModId());
}
sanityCheckModId();
modLog = LogManager.getLogger(getModId());
}
private void sanityCheckModId()
@@ -217,15 +211,15 @@ public class FMLModContainer implements ModContainer
modMetadata.requiredMods = info.requirements;
modMetadata.dependencies = info.dependencies;
modMetadata.dependants = info.dependants;
modLog.trace("Parsed dependency info : Requirements: {} After:{} Before:{}", info.requirements, info.dependencies, info.dependants);
FMLLog.log.trace("Parsed dependency info for {}: Requirements: {} After:{} Before:{}", getModId(), info.requirements, info.dependencies, info.dependants);
}
else
{
modLog.trace("Using mcmod dependency info : {} {} {}", modMetadata.requiredMods, modMetadata.dependencies, modMetadata.dependants);
FMLLog.log.trace("Using mcmod dependency info for {}: {} {} {}", getModId(), modMetadata.requiredMods, modMetadata.dependencies, modMetadata.dependants);
}
if (Strings.isNullOrEmpty(modMetadata.name))
{
modLog.info("Mod {} is missing the required element 'name'. Substituting {}", getModId(), getModId());
FMLLog.log.info("Mod {} is missing the required element 'name'. Substituting {}", getModId(), getModId());
modMetadata.name = getModId();
}
internalVersion = (String)descriptor.get("version");
@@ -235,18 +229,18 @@ public class FMLModContainer implements ModContainer
if (versionProps != null)
{
internalVersion = versionProps.getProperty(getModId() + ".version");
modLog.debug("Found version {} for mod {} in version.properties, using", internalVersion, getModId());
FMLLog.log.debug("Found version {} for mod {} in version.properties, using", internalVersion, getModId());
}
}
if (Strings.isNullOrEmpty(internalVersion) && !Strings.isNullOrEmpty(modMetadata.version))
{
modLog.warn("Mod {} is missing the required element 'version' and a version.properties file could not be found. Falling back to metadata version {}", getModId(), modMetadata.version);
FMLLog.log.warn("Mod {} is missing the required element 'version' and a version.properties file could not be found. Falling back to metadata version {}", getModId(), modMetadata.version);
internalVersion = modMetadata.version;
}
if (Strings.isNullOrEmpty(internalVersion))
{
modLog.warn("Mod {} is missing the required element 'version' and no fallback can be found. Substituting '1.0'.", getModId());
FMLLog.log.warn("Mod {} is missing the required element 'version' and no fallback can be found. Substituting '1.0'.", getModId());
modMetadata.version = internalVersion = "1.0";
}
@@ -274,7 +268,7 @@ public class FMLModContainer implements ModContainer
}
catch (MalformedURLException e)
{
modLog.debug("Specified json URL invalid: {}", jsonURL);
FMLLog.log.debug("Specified json URL for mod '{}' is invalid: {}", getModId(), jsonURL);
}
}
}
@@ -284,7 +278,7 @@ public class FMLModContainer implements ModContainer
{
try
{
modLog.debug("Attempting to load the file version.properties from {} to locate a version number for {}", getSource().getName(), getModId());
FMLLog.log.debug("Attempting to load the file version.properties from {} to locate a version number for mod {}", getSource().getName(), getModId());
Properties version = null;
if (getSource().isFile())
{
@@ -321,7 +315,7 @@ public class FMLModContainer implements ModContainer
}
catch (IOException e)
{
modLog.trace("Failed to find a usable version.properties file");
FMLLog.log.trace("Failed to find a usable version.properties file for mod {}", getModId());
return null;
}
}
@@ -373,7 +367,7 @@ public class FMLModContainer implements ModContainer
{
if (this.enabled)
{
modLog.debug("Enabling mod {}", getModId());
FMLLog.log.debug("Enabling mod {}", getModId());
this.eventBus = bus;
this.controller = controller;
eventBus.register(this);
@@ -403,7 +397,7 @@ public class FMLModContainer implements ModContainer
}
else
{
modLog.error("The mod {} appears to have an invalid event annotation {}. This annotation can only apply to methods with recognized event arguments - it will not be called", getModId(), a.annotationType().getSimpleName());
FMLLog.log.error("The mod {} appears to have an invalid event annotation {}. This annotation can only apply to methods with recognized event arguments - it will not be called", getModId(), a.annotationType().getSimpleName());
}
}
else if (a.annotationType().equals(Mod.InstanceFactory.class))
@@ -415,11 +409,11 @@ public class FMLModContainer implements ModContainer
}
else if (!(Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0))
{
modLog.error("The InstanceFactory annotation can only apply to a static method, taking zero arguments - it will be ignored on {}({})", m.getName(), Arrays.asList(m.getParameterTypes()));
FMLLog.log.error("The InstanceFactory annotation can only apply to a static method, taking zero arguments - it will be ignored on {}({}) for mod {}", m.getName(), Arrays.asList(m.getParameterTypes()), getModId());
}
else if (factoryMethod != null)
{
modLog.error("The InstanceFactory annotation can only be used once, the application to {}({}) will be ignored", m.getName(), Arrays.asList(m.getParameterTypes()));
FMLLog.log.error("The InstanceFactory annotation can only be used once, the application to {}({}) will be ignored for mod {}", m.getName(), Arrays.asList(m.getParameterTypes()), getModId());
}
}
}
@@ -486,7 +480,7 @@ public class FMLModContainer implements ModContainer
}
catch (ReflectiveOperationException e)
{
modLog.warn("Attempting to load @{} in class {} for {} and failing", annotationName, targets.getClassName(), mc.getModId(), e);
FMLLog.log.warn("Attempting to load @{} in class {} for {} and failing", annotationName, targets.getClassName(), mc.getModId(), e);
}
}
if (f != null)
@@ -497,7 +491,7 @@ public class FMLModContainer implements ModContainer
target = modInstance;
if (!modInstance.getClass().equals(clz))
{
modLog.warn("Unable to inject @{} in non-static field {}.{} for {} as it is NOT the primary mod instance", annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId());
FMLLog.log.warn("Unable to inject @{} in non-static field {}.{} for {} as it is NOT the primary mod instance", annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId());
continue;
}
}
@@ -538,7 +532,7 @@ public class FMLModContainer implements ModContainer
{
warnLevel = Level.TRACE;
}
modLog.log(warnLevel, "The mod {} is expecting signature {} for source {}, however there is no signature matching that description", getModId(), expectedFingerprint, source.getName());
FMLLog.log.log(warnLevel, "The mod {} is expecting signature {} for source {}, however there is no signature matching that description", getModId(), expectedFingerprint, source.getName());
}
else
{
@@ -575,7 +569,7 @@ public class FMLModContainer implements ModContainer
}
Method factoryMethod = gatherAnnotations(clazz);
modInstance = getLanguageAdapter().getNewInstance(this, clazz, modClassLoader, factoryMethod);
NetworkRegistry.INSTANCE.register(this, clazz, (String)(descriptor.containsKey("acceptableRemoteVersions") ? descriptor.get("acceptableRemoteVersions") : null), event.getASMHarvestedData());
NetworkRegistry.INSTANCE.register(this, clazz, (String)(descriptor.getOrDefault("acceptableRemoteVersions", null)), event.getASMHarvestedData());
if (fingerprintNotPresent)
{
eventBus.post(new FMLFingerprintViolationEvent(source.isDirectory(), source, ImmutableSet.copyOf(this.sourceFingerprints), expectedFingerprint));
@@ -131,7 +131,7 @@ public class LoadController
}
else
{
LogManager.getLogger(mod.getModId()).warn("Mod {} has been disabled through configuration", mod.getModId());
FMLLog.log.warn("Mod {} has been disabled through configuration", mod.getModId());
modStates.put(mod.getModId(), ModState.UNLOADED);
modStates.put(mod.getModId(), ModState.DISABLED);
}
@@ -266,7 +266,7 @@ public class LoadController
{
if (av.getLabel()!= null && requirements.contains(av.getLabel()) && modStates.containsEntry(av.getLabel(),ModState.ERRORED))
{
LogManager.getLogger(modId).error("Skipping event {} and marking errored mod {} since required dependency {} has errored", stateEvent.getEventType(), modId, av.getLabel());
FMLLog.log.error("Skipping event {} and marking errored mod {} since required dependency {} has errored", stateEvent.getEventType(), modId, av.getLabel());
modStates.put(modId, ModState.ERRORED);
return;
}
@@ -274,9 +274,9 @@ public class LoadController
activeContainer = mc;
stateEvent.applyModContainer(mc);
ThreadContext.put("mod", modId);
LogManager.getLogger(modId).trace("Sending event {} to mod {}", stateEvent.getEventType(), modId);
FMLLog.log.trace("Sending event {} to mod {}", stateEvent.getEventType(), modId);
eventChannels.get(modId).post(stateEvent);
LogManager.getLogger(modId).trace("Sent event {} to mod {}", stateEvent.getEventType(), modId);
FMLLog.log.trace("Sent event {} to mod {}", stateEvent.getEventType(), modId);
ThreadContext.remove("mod");
activeContainer = null;
if (stateEvent instanceof FMLStateEvent)
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.io.IOUtils;
import net.minecraft.launchwrapper.LaunchClassLoader;
@@ -42,8 +43,6 @@ import net.minecraftforge.fml.relauncher.Side;
import com.google.common.io.ByteStreams;
import static net.minecraftforge.fml.common.FMLLog.log;
public class FMLSanityChecker implements IFMLCallHook
{
private static final String FMLFINGERPRINT = "51:0A:FB:4C:AF:A4:A0:F2:F5:CF:C5:0E:B4:CC:3C:30:24:4A:E3:8E".toLowerCase().replace(":", "");
@@ -71,17 +70,17 @@ public class FMLSanityChecker implements IFMLCallHook
String fingerprint = CertificateHelper.getFingerprint(cert);
if (fingerprint.equals(FMLFINGERPRINT))
{
log.info("Found valid fingerprint for FML. Certificate fingerprint {}", fingerprint);
FMLLog.log.info("Found valid fingerprint for FML. Certificate fingerprint {}", fingerprint);
goodFML = true;
}
else if (fingerprint.equals(FORGEFINGERPRINT))
{
log.info("Found valid fingerprint for Minecraft Forge. Certificate fingerprint {}", fingerprint);
FMLLog.log.info("Found valid fingerprint for Minecraft Forge. Certificate fingerprint {}", fingerprint);
goodFML = true;
}
else
{
log.error("Found invalid fingerprint for FML: {}", fingerprint);
FMLLog.log.error("Found invalid fingerprint for FML: {}", fingerprint);
}
}
}
@@ -133,7 +132,7 @@ public class FMLSanityChecker implements IFMLCallHook
String fingerprint = CertificateHelper.getFingerprint(cert);
if (fingerprint.equals(MCFINGERPRINT))
{
log.info("Found valid fingerprint for Minecraft. Certificate fingerprint {}", fingerprint);
FMLLog.log.info("Found valid fingerprint for Minecraft. Certificate fingerprint {}", fingerprint);
goodMC = true;
}
}
@@ -141,7 +140,7 @@ public class FMLSanityChecker implements IFMLCallHook
}
catch (Throwable e)
{
log.error("A critical error occurred trying to read the minecraft jar file", e);
FMLLog.log.error("A critical error occurred trying to read the minecraft jar file", e);
}
finally
{
@@ -154,11 +153,11 @@ public class FMLSanityChecker implements IFMLCallHook
}
if (!goodMC)
{
log.error("The minecraft jar {} appears to be corrupt! There has been CRITICAL TAMPERING WITH MINECRAFT, it is highly unlikely minecraft will work! STOP NOW, get a clean copy and try again!", codeSource.getLocation().getFile());
FMLLog.log.error("The minecraft jar {} appears to be corrupt! There has been CRITICAL TAMPERING WITH MINECRAFT, it is highly unlikely minecraft will work! STOP NOW, get a clean copy and try again!", codeSource.getLocation().getFile());
if (!Boolean.parseBoolean(System.getProperty("fml.ignoreInvalidMinecraftCertificates","false")))
{
log.error("For your safety, FML will not launch minecraft. You will need to fetch a clean version of the minecraft jar file");
log.error("Technical information: The class net.minecraft.client.ClientBrandRetriever should have been associated with the minecraft jar file, " +
FMLLog.log.error("For your safety, FML will not launch minecraft. You will need to fetch a clean version of the minecraft jar file");
FMLLog.log.error("Technical information: The class net.minecraft.client.ClientBrandRetriever should have been associated with the minecraft jar file, " +
"and should have returned us a valid, intact minecraft jar location. This did not work. Either you have modified the minecraft jar file (if so " +
"run the forge installer again), or you are using a base editing jar that is changing this class (and likely others too). If you REALLY " +
"want to run minecraft in this configuration, add the flag -Dfml.ignoreInvalidMinecraftCertificates=true to the 'JVM settings' in your launcher profile.");
@@ -166,13 +165,13 @@ public class FMLSanityChecker implements IFMLCallHook
}
else
{
log.error("FML has been ordered to ignore the invalid or missing minecraft certificate. This is very likely to cause a problem!");
log.error("Technical information: ClientBrandRetriever was at {}, there were {} certificates for it", codeSource.getLocation(), certCount);
FMLLog.log.error("FML has been ordered to ignore the invalid or missing minecraft certificate. This is very likely to cause a problem!");
FMLLog.log.error("Technical information: ClientBrandRetriever was at {}, there were {} certificates for it", codeSource.getLocation(), certCount);
}
}
if (!goodFML)
{
log.error("FML appears to be missing any signature data. This is not a good thing");
FMLLog.log.error("FML appears to be missing any signature data. This is not a good thing");
}
return null;
}
@@ -151,11 +151,9 @@ public class FMLPreInitializationEvent extends FMLStateEvent
*/
public Logger getModLog()
{
Logger log = LogManager.getLogger(modContainer.getModId());
return log;
return LogManager.getLogger(modContainer.getModId());
}
/**
* Retrieve the FML signing certificates, if any. Validate these against the
* published FML certificates in your mod, if you wish.
@@ -37,7 +37,7 @@ public class FMLServerTweaker extends FMLTweaker {
if (System.getProperty("log4j.configurationFile") == null)
{
System.setProperty("log4j.configurationFile", "log4j2_server.xml");
System.setProperty("log4j.configurationFile", "log4j2.xml");
((LoggerContext) LogManager.getContext(false)).reconfigure();
}
}
@@ -129,7 +129,7 @@ public class FMLTweaker implements ITweaker {
}
catch (URISyntaxException e)
{
LogManager.getLogger("FMLTWEAK").log(Level.ERROR, "Missing URI information for FML tweak");
LogManager.getLogger("FML.TWEAK").error("Missing URI information for FML tweak");
throw new RuntimeException(e);
}
}
@@ -48,7 +48,7 @@ public class Yggdrasil
}
catch (AuthenticationException e)
{
LogManager.getLogger("FMLTWEAK").error("-- Login failed! {}", e.getMessage(), e);
LogManager.getLogger("FML.TWEAK").error("-- Login failed!", e);
throw new RuntimeException(e); // don't set other variables
}
@@ -31,16 +31,13 @@ import java.util.jar.JarFile;
import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
import net.minecraftforge.fml.repackage.com.nothome.delta.Delta;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import java.util.logging.Logger;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
@@ -56,7 +53,8 @@ public class GenDiffSet {
String outputDir = args[3]; //Path to place generated .binpatch
String killTarget = args[4]; //"true" if we should destroy the target file if it generated a successful .binpatch
LogManager.getLogger("GENDIFF").log(Level.INFO, String.format("Creating patches at %s for %s from %s", outputDir, sourceJar, targetDir));
Logger logger = LogManager.getLogger("FML.GENDIFF");
logger.info("Creating patches at {} for {} from {}", outputDir, sourceJar, targetDir);
Delta delta = new Delta();
FMLDeobfuscatingRemapper remapper = FMLDeobfuscatingRemapper.INSTANCE;
remapper.setupLoadOnly(deobfData, false);
@@ -109,11 +107,11 @@ public class GenDiffSet {
File target = new File(outputDir, targetClassName+".binpatch");
target.getParentFile().mkdirs();
Files.write(diffOut.toByteArray(), target);
Logger.getLogger("GENDIFF").info(String.format("Wrote patch for %s (%s) at %s",name, targetClassName, target.getAbsolutePath()));
logger.info("Wrote patch for {} ({}) at {}", name, targetClassName, target.getAbsolutePath());
if (kill)
{
targetFile.delete();
Logger.getLogger("GENDIFF").info(String.format(" Deleted target: %s", targetFile.toString()));
logger.info(" Deleted target: {}", targetFile);
}
}
}
@@ -28,10 +28,9 @@ import java.util.Set;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.LoaderException;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public final class DependencyParser
{
@@ -42,7 +41,6 @@ public final class DependencyParser
public final List<ArtifactVersion> dependants = new ArrayList<>();
}
private static final Logger LOGGER = LogManager.getLogger("FML");
private static final ImmutableList<String> DEPENDENCY_INSTRUCTIONS = ImmutableList.of("client", "server", "required", "before", "after");
private static final Splitter DEPENDENCY_INSTRUCTIONS_SPLITTER = Splitter.on("-").omitEmptyStrings().trimResults();
private static final Splitter DEPENDENCY_PART_SPLITTER = Splitter.on(":").omitEmptyStrings().trimResults();
@@ -189,15 +187,15 @@ public final class DependencyParser
{
if (Strings.isNullOrEmpty(depModId))
{
LOGGER.error(new DependencyParserException(modId, dep, "The modId is null or empty").getMessage());
FMLLog.log.error(new DependencyParserException(modId, dep, "The modId is null or empty").getMessage());
}
else if (depModId.length() > 64)
{
LOGGER.error(new DependencyParserException(modId, dep, String.format("The modId '%s' is longer than the maximum of 64 characters.", depModId)).getMessage());
FMLLog.log.error(new DependencyParserException(modId, dep, String.format("The modId '%s' is longer than the maximum of 64 characters.", depModId)).getMessage());
}
else if (!depModId.equals(depModId.toLowerCase(Locale.ENGLISH)))
{
LOGGER.error(new DependencyParserException(modId, dep, String.format("The modId '%s' must be all lowercase.", depModId)).getMessage());
FMLLog.log.error(new DependencyParserException(modId, dep, String.format("The modId '%s' must be all lowercase.", depModId)).getMessage());
}
}