From 0c6019da8f4f551801f9438c48d51bd10a127fa7 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 30 Jan 2013 18:57:21 -0500 Subject: [PATCH] A log of logging cleanup. FML will now read logging.properties to configure logging channels a couple of times during startup. You should be able to filter a lot of messages based on things like modid and certain FML related features that can be noisy like item tracking. Should close #175 --- .../cpw/mods/fml/client/SpriteHelper.java | 6 +- .../cpw/mods/fml/client/TextureFXManager.java | 13 ++-- .../modloader/ModLoaderClientHelper.java | 16 ++--- .../minecraft/src/FMLRenderAccessLibrary.java | 6 +- fml/commands.patch | 33 ++++++--- .../cpw/mods/fml/common/FMLCommonHandler.java | 7 +- .../mods/fml/common/FMLDummyContainer.java | 5 +- fml/common/cpw/mods/fml/common/FMLLog.java | 15 ++++ .../cpw/mods/fml/common/FMLModContainer.java | 26 +++---- .../cpw/mods/fml/common/LoadController.java | 32 ++++++--- fml/common/cpw/mods/fml/common/Loader.java | 40 +++++++---- .../cpw/mods/fml/common/ModClassLoader.java | 2 +- .../fml/common/discovery/ModDiscoverer.java | 2 +- .../event/FMLPreInitializationEvent.java | 2 + .../mods/fml/common/registry/GameData.java | 18 ++--- .../fml/common/registry/LanguageRegistry.java | 6 +- .../mods/fml/relauncher/FMLRelaunchLog.java | 72 +++++++++++++++---- 17 files changed, 203 insertions(+), 98 deletions(-) diff --git a/fml/client/cpw/mods/fml/client/SpriteHelper.java b/fml/client/cpw/mods/fml/client/SpriteHelper.java index e65439e6a..0c2a6133f 100644 --- a/fml/client/cpw/mods/fml/client/SpriteHelper.java +++ b/fml/client/cpw/mods/fml/client/SpriteHelper.java @@ -80,7 +80,7 @@ public class SpriteHelper initMCSpriteMaps(); } if (spriteInfo.containsKey(file)) { - FMLCommonHandler.instance().getFMLLogger().finer(String.format("Duplicate attempt to register a sprite file %s for overriding -- ignoring",file)); + FMLLog.log("fml.TextureManager", Level.FINE, "Duplicate attempt to register a sprite file %s for overriding -- ignoring",file); return; } spriteInfo.put(file, toBitSet(spriteMap)); @@ -98,7 +98,7 @@ public class SpriteHelper if (slots == null) { Exception ex = new Exception(String.format("Invalid getUniqueSpriteIndex call for texture: %s", path)); - FMLLog.log(Level.SEVERE, ex, "A critical error has been detected with sprite overrides"); + FMLLog.log("fml.TextureManager", Level.SEVERE, ex, "A critical error has been detected with sprite overrides"); FMLCommonHandler.instance().raiseException(ex,"Invalid request to getUniqueSpriteIndex",true); } @@ -107,7 +107,7 @@ public class SpriteHelper if (ret == -1) { Exception ex = new Exception(String.format("No more sprite indicies left for: %s", path)); - FMLLog.log(Level.SEVERE, ex, "There are no sprite indicies left for %s", path); + FMLLog.log("fml.TextureManager", Level.SEVERE, ex, "There are no sprite indicies left for %s", path); FMLCommonHandler.instance().raiseException(ex,"No more sprite indicies left", true); } return ret; diff --git a/fml/client/cpw/mods/fml/client/TextureFXManager.java b/fml/client/cpw/mods/fml/client/TextureFXManager.java index d041348ae..fe1fe5575 100644 --- a/fml/client/cpw/mods/fml/client/TextureFXManager.java +++ b/fml/client/cpw/mods/fml/client/TextureFXManager.java @@ -15,6 +15,7 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.logging.Level; import javax.imageio.ImageIO; @@ -77,7 +78,7 @@ public class TextureFXManager } catch (Exception e) { - FMLLog.warning("Texture FX %s has failed to animate. Likely caused by a texture pack change that they did not respond correctly to", name); + FMLLog.log("fml.TextureManager", Level.WARNING, "Texture FX %s has failed to animate. Likely caused by a texture pack change that they did not respond correctly to", name); if (ifx != null) { ifx.setErrored(true); @@ -93,7 +94,7 @@ public class TextureFXManager int target = ((dim.width >> 4) * (dim.height >> 4)) << 2; if (effect.field_76852_a.length != target) { - FMLLog.warning("Detected a texture FX sizing discrepancy in %s (%d, %d)", name, effect.field_76852_a.length, target); + FMLLog.log("fml.TextureManager", Level.WARNING, "Detected a texture FX sizing discrepancy in %s (%d, %d)", name, effect.field_76852_a.length, target); ifx.setErrored(true); return false; } @@ -232,7 +233,7 @@ public class TextureFXManager for (OverrideInfo animationOverride : animationSet) { renderer.func_78355_a(animationOverride.textureFX); addedTextureFX.add(animationOverride.textureFX); - FMLCommonHandler.instance().getFMLLogger().finer(String.format("Registered texture override %d (%d) on %s (%d)", animationOverride.index, animationOverride.textureFX.field_76850_b, animationOverride.textureFX.getClass().getSimpleName(), animationOverride.textureFX.field_76847_f)); + FMLLog.log("fml.TextureManager", Level.FINE, "Registered texture override %d (%d) on %s (%d)", animationOverride.index, animationOverride.textureFX.field_76850_b, animationOverride.textureFX.getClass().getSimpleName(), animationOverride.textureFX.field_76847_f); } for (String fileToOverride : overrideInfo.keySet()) { @@ -243,11 +244,11 @@ public class TextureFXManager ModTextureStatic mts=new ModTextureStatic(override.index, 1, override.texture, image); renderer.func_78355_a(mts); addedTextureFX.add(mts); - FMLCommonHandler.instance().getFMLLogger().finer(String.format("Registered texture override %d (%d) on %s (%d)", override.index, mts.field_76850_b, override.texture, mts.field_76847_f)); + FMLLog.log("fml.TextureManager", Level.FINE, "Registered texture override %d (%d) on %s (%d)", override.index, mts.field_76850_b, override.texture, mts.field_76847_f); } catch (IOException e) { - FMLCommonHandler.instance().getFMLLogger().throwing("FMLClientHandler", "registerTextureOverrides", e); + FMLLog.log("fml.TextureManager", Level.WARNING, e, "Exception occurred registering texture override for %s", fileToOverride); } } } @@ -294,7 +295,7 @@ public class TextureFXManager info.override = overridingTexturePath; info.texture = textureToOverride; overrideInfo.put(textureToOverride, info); - FMLLog.fine("Overriding %s @ %d with %s. %d slots remaining",textureToOverride, location, overridingTexturePath, SpriteHelper.freeSlotCount(textureToOverride)); + FMLLog.log("fml.TextureManager", Level.FINE, "Overriding %s @ %d with %s. %d slots remaining",textureToOverride, location, overridingTexturePath, SpriteHelper.freeSlotCount(textureToOverride)); } public BufferedImage loadImageFromTexturePack(RenderEngine renderEngine, String path) throws IOException diff --git a/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java b/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java index 6312484b7..4d3016653 100644 --- a/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java +++ b/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java @@ -57,38 +57,38 @@ public class ModLoaderClientHelper implements IModLoaderSidedHelper public static void handleFinishLoadingFor(ModLoaderModContainer mc, Minecraft game) { - FMLLog.finer("Handling post startup activities for ModLoader mod %s", mc.getModId()); + FMLLog.log(mc.getModId(), Level.FINE, "Handling post startup activities for ModLoader mod %s", mc.getModId()); BaseMod mod = (BaseMod) mc.getMod(); Map, Render> renderers = Maps.newHashMap(RenderManager.field_78727_a.field_78729_o); try { - FMLLog.finest("Requesting renderers from basemod %s", mc.getModId()); + FMLLog.log(mc.getModId(), Level.FINEST, "Requesting renderers from basemod %s", mc.getModId()); mod.addRenderer(renderers); - FMLLog.finest("Received %d renderers from basemod %s", renderers.size(), mc.getModId()); + FMLLog.log(mc.getModId(), Level.FINEST, "Received %d renderers from basemod %s", renderers.size(), mc.getModId()); } catch (Exception e) { - FMLLog.log(Level.SEVERE, e, "A severe problem was detected with the mod %s during the addRenderer call. Continuing, but expect odd results", mc.getModId()); + FMLLog.log(mc.getModId(), Level.SEVERE, e, "A severe problem was detected with the mod %s during the addRenderer call. Continuing, but expect odd results", mc.getModId()); } MapDifference, Render> difference = Maps.difference(RenderManager.field_78727_a.field_78729_o, renderers, Equivalences.identity()); for ( Entry, Render> e : difference.entriesOnlyOnLeft().entrySet()) { - FMLLog.warning("The mod %s attempted to remove an entity renderer %s from the entity map. This will be ignored.", mc.getModId(), e.getKey().getName()); + FMLLog.log(mc.getModId(), Level.WARNING, "The mod %s attempted to remove an entity renderer %s from the entity map. This will be ignored.", mc.getModId(), e.getKey().getName()); } for (Entry, Render> e : difference.entriesOnlyOnRight().entrySet()) { - FMLLog.finest("Registering ModLoader entity renderer %s as instance of %s", e.getKey().getName(), e.getValue().getClass().getName()); + FMLLog.log(mc.getModId(), Level.FINEST, "Registering ModLoader entity renderer %s as instance of %s", e.getKey().getName(), e.getValue().getClass().getName()); RenderingRegistry.registerEntityRenderingHandler(e.getKey(), e.getValue()); } for (Entry, ValueDifference> e : difference.entriesDiffering().entrySet()) { - FMLLog.finest("Registering ModLoader entity rendering override for %s as instance of %s", e.getKey().getName(), e.getValue().rightValue().getClass().getName()); + FMLLog.log(mc.getModId(), Level.FINEST, "Registering ModLoader entity rendering override for %s as instance of %s", e.getKey().getName(), e.getValue().rightValue().getClass().getName()); RenderingRegistry.registerEntityRenderingHandler(e.getKey(), e.getValue().rightValue()); } @@ -98,7 +98,7 @@ public class ModLoaderClientHelper implements IModLoaderSidedHelper } catch (Exception e) { - FMLLog.log(Level.SEVERE, e, "A severe problem was detected with the mod %s during the registerAnimation call. Continuing, but expect odd results", mc.getModId()); + FMLLog.log(mc.getModId(), Level.SEVERE, e, "A severe problem was detected with the mod %s during the registerAnimation call. Continuing, but expect odd results", mc.getModId()); } } diff --git a/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java b/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java index 2032e8aed..18d715967 100644 --- a/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java +++ b/fml/client/net/minecraft/src/FMLRenderAccessLibrary.java @@ -41,12 +41,14 @@ public class FMLRenderAccessLibrary { public static Logger getLogger() { - return FMLLog.getLogger(); + Logger l = Logger.getLogger("FMLRenderAccessLibrary"); + l.setParent(FMLLog.getLogger()); + return l; } public static void log(Level level, String message) { - FMLLog.log(level, message); + FMLLog.log("FMLRenderAccessLibrary", level, message); } public static void log(Level level, String message, Throwable throwable) diff --git a/fml/commands.patch b/fml/commands.patch index 2e3750e84..a83379470 100644 --- a/fml/commands.patch +++ b/fml/commands.patch @@ -18,7 +18,18 @@ if not os.path.exists(os.path.join(binlk[side], os.path.normpath(testlk[side] + '.class'))): return False return True -@@ -1062,7 +1066,7 @@ +@@ -1029,6 +1033,10 @@ + pathsrclk = {CLIENT: self.srcclient, SERVER: self.srcserver} + pathlog = {CLIENT: self.clientrecomplog, SERVER: self.serverrecomplog} + ++ if side == SERVER: #Disable server because FML recombines it into client ++ self.logger.info('Server side recompiling skipped, this is normal') ++ return ++ + if not os.path.exists(pathbinlk[side]): + os.makedirs(pathbinlk[side]) + +@@ -1062,7 +1070,7 @@ raise def startserver(self): @@ -27,7 +38,7 @@ classpath = [os.path.join('..', p) for p in classpath] classpath = os.pathsep.join(classpath) os.chdir(self.dirjars) -@@ -1070,7 +1074,7 @@ +@@ -1070,7 +1078,7 @@ self.runmc(forkcmd) def startclient(self): @@ -36,7 +47,7 @@ classpath = [os.path.join('..', p) for p in classpath] classpath = os.pathsep.join(classpath) natives = os.path.join('..', self.dirnatives) -@@ -1197,20 +1201,20 @@ +@@ -1197,20 +1205,20 @@ with open(self.csvmethods, 'rb') as fh: methodsreader = csv.DictReader(fh) for row in methodsreader: @@ -60,7 +71,7 @@ names['params'][row['param']] = row['name'] regexps = { -@@ -1344,13 +1348,13 @@ +@@ -1344,13 +1352,13 @@ methods = {} for row in methodsreader: #HINT: Only include methods that have a non-empty description @@ -76,7 +87,7 @@ fields[row['searge']] = row['desc'].replace('*/', '* /') regexps = { -@@ -1427,7 +1431,7 @@ +@@ -1427,7 +1435,7 @@ self.runcmd(forkcmd) return True @@ -85,7 +96,7 @@ if not reobf: md5lk = {CLIENT: self.md5client, SERVER: self.md5server} else: -@@ -1442,6 +1446,9 @@ +@@ -1442,6 +1450,9 @@ class_path = '' else: class_path += '/' @@ -95,7 +106,7 @@ for class_file in fnmatch.filter(filelist, '*.class'): class_name = class_path + os.path.splitext(class_file)[0] bin_file = os.path.normpath(os.path.join(path, class_file)) -@@ -1535,6 +1542,8 @@ +@@ -1535,6 +1546,8 @@ if not os.path.exists(outpathlk[side]): os.makedirs(outpathlk[side]) @@ -104,7 +115,7 @@ # HINT: We extract the modified class files with closing(zipfile.ZipFile(jarlk[side])) as zipjar: for in_class in trgclasses: -@@ -1548,6 +1557,23 @@ +@@ -1548,6 +1561,23 @@ out_class = out_class.replace(self.nullpkg, '') if out_class[0] == '/': out_class = out_class[1:] @@ -128,7 +139,7 @@ try: zipjar.extract(out_class, outpathlk[side]) self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), outpathlk[side], out_class) -@@ -1594,6 +1620,9 @@ +@@ -1594,6 +1624,9 @@ sys.exit(1) for entry in newfiles: @@ -138,7 +149,7 @@ if entry[3] == 'U': self.logger.info('Retrieving file from server : %s', entry[0]) cur_file = os.path.normpath(entry[0]) -@@ -1614,6 +1643,9 @@ +@@ -1614,6 +1647,9 @@ md5reoblk = {CLIENT: self.md5reobfclient, SERVER: self.md5reobfserver} outpathlk = {CLIENT: self.srcmodclient, SERVER: self.srcmodserver} src = {CLIENT: self.srcclient, SERVER: self.srcserver} @@ -148,7 +159,7 @@ # HINT: We need a table for the old md5 and the new ones md5table = {} -@@ -1656,3 +1688,6 @@ +@@ -1656,3 +1692,6 @@ except IOError: self.logger.error('* File %s copy failed', in_class) diff --git a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java index eb13499af..43e6715c7 100644 --- a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import net.minecraft.crash.CrashReport; @@ -92,10 +93,10 @@ public class FMLCommonHandler public void beginLoading(IFMLSidedHandler handler) { sidedDelegate = handler; - FMLLog.info("Attempting early MinecraftForge initialization"); + FMLLog.log("MinecraftForge", Level.INFO, "Attempting early MinecraftForge initialization"); callForgeMethod("initialize"); callForgeMethod("registerCrashCallable"); - FMLLog.info("Completed early MinecraftForge initialization"); + FMLLog.log("MinecraftForge", Level.INFO, "Completed early MinecraftForge initialization"); } public void rescheduleTicks(Side side) @@ -189,7 +190,7 @@ public class FMLCommonHandler */ public void raiseException(Throwable exception, String message, boolean stopGame) { - FMLCommonHandler.instance().getFMLLogger().throwing("FMLHandler", "raiseException", exception); + FMLLog.log(Level.SEVERE, exception, "Something raised an exception. The message was '%s'. 'stopGame' is %b", message, stopGame); if (stopGame) { getSidedDelegate().haltGame(message,exception); diff --git a/fml/common/cpw/mods/fml/common/FMLDummyContainer.java b/fml/common/cpw/mods/fml/common/FMLDummyContainer.java index 37edd2ce6..d9048d1e6 100644 --- a/fml/common/cpw/mods/fml/common/FMLDummyContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLDummyContainer.java @@ -18,6 +18,7 @@ import java.security.cert.Certificate; import java.util.Arrays; import java.util.Map; import java.util.Set; +import java.util.logging.Level; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; @@ -96,12 +97,12 @@ public class FMLDummyContainer extends DummyModContainer implements WorldAccessC ModContainer container = Loader.instance().getIndexedModList().get(modId); if (container == null) { - FMLLog.severe("This world was saved with mod %s which appears to be missing, things may not work well", modId); + FMLLog.log("fml.ModTracker", Level.SEVERE, "This world was saved with mod %s which appears to be missing, things may not work well", modId); continue; } if (!modVersion.equals(container.getVersion())) { - FMLLog.info("This world was saved with mod %s version %s and it is now at version %s, things may not work well", modId, modVersion, container.getVersion()); + FMLLog.log("fml.ModTracker", Level.INFO, "This world was saved with mod %s version %s and it is now at version %s, things may not work well", modId, modVersion, container.getVersion()); } } } diff --git a/fml/common/cpw/mods/fml/common/FMLLog.java b/fml/common/cpw/mods/fml/common/FMLLog.java index f9e6d676d..cf8dba8c5 100644 --- a/fml/common/cpw/mods/fml/common/FMLLog.java +++ b/fml/common/cpw/mods/fml/common/FMLLog.java @@ -7,11 +7,21 @@ public class FMLLog { private static cpw.mods.fml.relauncher.FMLRelaunchLog coreLog = cpw.mods.fml.relauncher.FMLRelaunchLog.log; + public static void log(String logChannel, Level level, String format, Object... data) + { + coreLog.log(logChannel, level, format, data); + } + public static void log(Level level, String format, Object... data) { coreLog.log(level, format, data); } + public static void log(String logChannel, Level level, Throwable ex, String format, Object... data) + { + coreLog.log(logChannel, level, ex, format, data); + } + public static void log(Level level, Throwable ex, String format, Object... data) { coreLog.log(level, ex, format, data); @@ -50,4 +60,9 @@ public class FMLLog { return coreLog.getLogger(); } + + public static void makeLog(String logChannel) + { + coreLog.makeLog(logChannel); + } } diff --git a/fml/common/cpw/mods/fml/common/FMLModContainer.java b/fml/common/cpw/mods/fml/common/FMLModContainer.java index 252aea20c..7fe9565c4 100644 --- a/fml/common/cpw/mods/fml/common/FMLModContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLModContainer.java @@ -164,15 +164,15 @@ public class FMLModContainer implements ModContainer modMetadata.requiredMods = requirements; modMetadata.dependencies = dependencies; modMetadata.dependants = dependants; - FMLLog.finest("Parsed dependency info : %s %s %s", requirements, dependencies, dependants); + FMLLog.log(getModId(), Level.FINEST, "Parsed dependency info : %s %s %s", requirements, dependencies, dependants); } else { - FMLLog.finest("Using mcmod dependency info : %s %s %s", modMetadata.requiredMods, modMetadata.dependencies, modMetadata.dependants); + FMLLog.log(getModId(), Level.FINEST, "Using mcmod dependency info : %s %s %s", modMetadata.requiredMods, modMetadata.dependencies, modMetadata.dependants); } if (Strings.isNullOrEmpty(modMetadata.name)) { - FMLLog.info("Mod %s is missing the required element 'name'. Substituting %s", getModId(), getModId()); + FMLLog.log(getModId(), Level.INFO,"Mod %s is missing the required element 'name'. Substituting %s", getModId(), getModId()); modMetadata.name = getModId(); } internalVersion = (String) descriptor.get("version"); @@ -182,18 +182,18 @@ public class FMLModContainer implements ModContainer if (versionProps != null) { internalVersion = versionProps.getProperty(getModId()+".version"); - FMLLog.fine("Found version %s for mod %s in version.properties, using", internalVersion, getModId()); + FMLLog.log(getModId(), Level.FINE, "Found version %s for mod %s in version.properties, using", internalVersion, getModId()); } } if (Strings.isNullOrEmpty(internalVersion) && !Strings.isNullOrEmpty(modMetadata.version)) { - FMLLog.warning("Mod %s is missing the required element 'version' and a version.properties file could not be found. Falling back to metadata version %s", getModId(), modMetadata.version); + FMLLog.log(getModId(), Level.WARNING, "Mod %s is missing the required element 'version' and a version.properties file could not be found. Falling back to metadata version %s", getModId(), modMetadata.version); internalVersion = modMetadata.version; } if (Strings.isNullOrEmpty(internalVersion)) { - FMLLog.warning("Mod %s is missing the required element 'version' and no fallback can be found. Substituting '1.0'.", getModId()); + FMLLog.log(getModId(), Level.WARNING, "Mod %s is missing the required element 'version' and no fallback can be found. Substituting '1.0'.", getModId()); modMetadata.version = internalVersion = "1.0"; } @@ -212,7 +212,7 @@ public class FMLModContainer implements ModContainer { try { - FMLLog.fine("Attempting to load the file version.properties from %s to locate a version number for %s", getSource().getName(), getModId()); + FMLLog.log(getModId(), Level.FINE,"Attempting to load the file version.properties from %s to locate a version number for %s", getSource().getName(), getModId()); Properties version = null; if (getSource().isFile()) { @@ -241,7 +241,7 @@ public class FMLModContainer implements ModContainer catch (Exception e) { Throwables.propagateIfPossible(e); - FMLLog.fine("Failed to find a usable version.properties file"); + FMLLog.log(getModId(), Level.FINEST, "Failed to find a usable version.properties file"); return null; } } @@ -293,7 +293,7 @@ public class FMLModContainer implements ModContainer { if (this.enabled) { - FMLLog.fine("Enabling mod %s", getModId()); + FMLLog.log(getModId(), Level.FINE, "Enabling mod %s", getModId()); this.eventBus = bus; this.controller = controller; eventBus.register(this); @@ -324,7 +324,7 @@ public class FMLModContainer implements ModContainer } else { - FMLLog.severe("The mod %s appears to have an invalid method annotation %s. This annotation can only apply to methods with argument types %s -it will not be called", getModId(), a.annotationType().getSimpleName(), Arrays.toString(paramTypes)); + FMLLog.log(getModId(), Level.SEVERE,"The mod %s appears to have an invalid method annotation %s. This annotation can only apply to methods with argument types %s -it will not be called", getModId(), a.annotationType().getSimpleName(), Arrays.toString(paramTypes)); } } } @@ -388,7 +388,7 @@ public class FMLModContainer implements ModContainer catch (Exception e) { Throwables.propagateIfPossible(e); - FMLLog.log(Level.WARNING, e, "Attempting to load @%s in class %s for %s and failing", annotationName, targets.getClassName(), mc.getModId()); + FMLLog.log(getModId(), Level.WARNING, e, "Attempting to load @%s in class %s for %s and failing", annotationName, targets.getClassName(), mc.getModId()); } } if (f != null) @@ -399,7 +399,7 @@ public class FMLModContainer implements ModContainer target = modInstance; if (!modInstance.getClass().equals(clz)) { - FMLLog.warning("Unable to inject @%s in non-static field %s.%s for %s as it is NOT the primary mod instance", annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId()); + FMLLog.log(getModId(), Level.WARNING, "Unable to inject @%s in non-static field %s.%s for %s as it is NOT the primary mod instance", annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId()); continue; } } @@ -445,7 +445,7 @@ public class FMLModContainer implements ModContainer { warnLevel = Level.FINER; } - FMLLog.log(warnLevel, "The mod %s is expecting signature %s for source %s, however there is no signature matching that description", getModId(), expectedFingerprint, source.getName()); + FMLLog.log(getModId(), warnLevel, "The mod %s is expecting signature %s for source %s, however there is no signature matching that description", getModId(), expectedFingerprint, source.getName()); } else { diff --git a/fml/common/cpw/mods/fml/common/LoadController.java b/fml/common/cpw/mods/fml/common/LoadController.java index 123e9962a..191346caf 100644 --- a/fml/common/cpw/mods/fml/common/LoadController.java +++ b/fml/common/cpw/mods/fml/common/LoadController.java @@ -95,19 +95,29 @@ public class LoadController StringBuilder sb = new StringBuilder(); printModStates(sb); FMLLog.getLogger().severe(sb.toString()); - FMLLog.severe("The following problems were captured during this phase"); - for (Entry error : errors.entries()) + if (errors.size()>0) { - FMLLog.log(Level.SEVERE, error.getValue(), "Caught exception from %s", error.getKey()); - if (error.getValue() instanceof IFMLHandledException) + FMLLog.severe("The following problems were captured during this phase"); + for (Entry error : errors.entries()) { - toThrow = error.getValue(); - } - else if (toThrow == null) - { - toThrow = error.getValue(); + FMLLog.log(Level.SEVERE, error.getValue(), "Caught exception from %s", error.getKey()); + if (error.getValue() instanceof IFMLHandledException) + { + toThrow = error.getValue(); + } + else if (toThrow == null) + { + toThrow = error.getValue(); + } } } + else + { + FMLLog.severe("The ForgeModLoader state engine has become corrupted. Probably, a state was missed by and invalid modification to a base class" + + "ForgeModLoader depends on. This is a critical error and not recoverable. Investigate any modifications to base classes outside of" + + "ForgeModLoader, especially Optifine, to see if there are fixes available."); + throw new RuntimeException("The ForgeModLoader state engine is invalid"); + } if (toThrow != null && toThrow instanceof RuntimeException) { throw (RuntimeException)toThrow; @@ -136,9 +146,9 @@ public class LoadController activeContainer = mc; String modId = mc.getModId(); stateEvent.applyModContainer(activeContainer()); - FMLLog.finer("Sending event %s to mod %s", stateEvent.getEventType(), modId); + FMLLog.log(modId, Level.FINEST, "Sending event %s to mod %s", stateEvent.getEventType(), modId); eventChannels.get(modId).post(stateEvent); - FMLLog.finer("Sent event %s to mod %s", stateEvent.getEventType(), modId); + FMLLog.log(modId, Level.FINEST, "Sent event %s to mod %s", stateEvent.getEventType(), modId); activeContainer = null; if (stateEvent instanceof FMLStateEvent) { diff --git a/fml/common/cpw/mods/fml/common/Loader.java b/fml/common/cpw/mods/fml/common/Loader.java index ba00126ee..04f4e0d83 100644 --- a/fml/common/cpw/mods/fml/common/Loader.java +++ b/fml/common/cpw/mods/fml/common/Loader.java @@ -61,6 +61,7 @@ import cpw.mods.fml.common.toposort.ModSortingException; import cpw.mods.fml.common.toposort.TopologicalSort; import cpw.mods.fml.common.versioning.ArtifactVersion; import cpw.mods.fml.common.versioning.VersionParser; +import cpw.mods.fml.relauncher.FMLRelaunchLog; /** * The loader class performs the actual loading of the mod code from disk. @@ -142,6 +143,7 @@ public class Loader private static File minecraftDir; private static List injectedContainers; + private File loggingProperties; public static Loader instance() { @@ -186,7 +188,7 @@ public class Loader */ private void sortModList() { - FMLLog.fine("Verifying mod requirements are satisfied"); + FMLLog.finer("Verifying mod requirements are satisfied"); try { BiMap modVersions = HashBiMap.create(); @@ -238,13 +240,13 @@ public class Loader } } - FMLLog.fine("All mod requirements are satisfied"); + FMLLog.finer("All mod requirements are satisfied"); ModSorter sorter = new ModSorter(getActiveModList(), namedMods); try { - FMLLog.fine("Sorting mods into an ordered list"); + FMLLog.finer("Sorting mods into an ordered list"); List sortedMods = sorter.sort(); // Reset active list to the sorted list modController.getActiveModList().clear(); @@ -253,7 +255,7 @@ public class Loader mods.removeAll(sortedMods); sortedMods.addAll(mods); mods = sortedMods; - FMLLog.fine("Mod sorting completed successfully"); + FMLLog.finer("Mod sorting completed successfully"); } catch (ModSortingException sortException) { @@ -266,17 +268,19 @@ public class Loader } finally { - FMLLog.fine("Mod sorting data:"); + FMLLog.fine("Mod sorting data"); + int unprintedMods = mods.size(); for (ModContainer mod : getActiveModList()) { if (!mod.isImmutable()) { FMLLog.fine("\t%s(%s:%s): %s (%s)", mod.getModId(), mod.getName(), mod.getVersion(), mod.getSource().getName(), mod.getSortingRules()); + unprintedMods--; } } - if (mods.size()==0) + if (unprintedMods == mods.size()) { - FMLLog.fine("No mods found to sort"); + FMLLog.fine("No user mods found to sort"); } } @@ -335,6 +339,10 @@ public class Loader identifyDuplicates(mods); namedMods = Maps.uniqueIndex(mods, new ModIdFunction()); FMLLog.info("Forge Mod Loader has identified %d mod%s to load", mods.size(), mods.size() != 1 ? "s" : ""); + for (String modId: namedMods.keySet()) + { + FMLLog.makeLog(modId); + } return discoverer; } @@ -435,6 +443,11 @@ public class Loader FMLLog.severe("Attempting to load configuration from %s, which is not a directory", canonicalConfigPath); throw new LoaderException(); } + + loggingProperties = new File(canonicalConfigDir, "logging.properties"); + FMLLog.info("Reading custom logging properties from %s", loggingProperties.getPath()); + FMLRelaunchLog.loadLogConfiguration(loggingProperties); + FMLLog.log(Level.OFF,"Logging level for ForgeModLoader logging is set to %s", FMLRelaunchLog.log.getLogger().getLevel()); } public List getModList() @@ -456,6 +469,9 @@ public class Loader modController.transition(LoaderState.LOADING); ModDiscoverer disc = identifyMods(); disableRequestedMods(); + FMLLog.fine("Reloading logging properties from %s", loggingProperties.getPath()); + FMLRelaunchLog.loadLogConfiguration(loggingProperties); + FMLLog.fine("Reloaded logging properties"); modController.distributeStateMessage(FMLLoadEvent.class); sortModList(); mods = ImmutableList.copyOf(mods); @@ -476,7 +492,7 @@ public class Loader } modController.transition(LoaderState.CONSTRUCTING); modController.distributeStateMessage(LoaderState.CONSTRUCTING, modClassLoader, disc.getASMTable()); - FMLLog.fine("Mod signature data:"); + FMLLog.fine("Mod signature data"); for (ModContainer mod : getActiveModList()) { FMLLog.fine("\t%s(%s:%s): %s (%s)", mod.getModId(), mod.getName(), mod.getVersion(), mod.getSource().getName(), CertificateHelper.getFingerprint(mod.getSigningCertificate())); @@ -489,22 +505,22 @@ public class Loader private void disableRequestedMods() { String forcedModList = System.getProperty("fml.modStates", ""); - FMLLog.fine("Received a system property request \'%s\'",forcedModList); + FMLLog.finer("Received a system property request \'%s\'",forcedModList); Map sysPropertyStateList = Splitter.on(CharMatcher.anyOf(";:")) .omitEmptyStrings().trimResults().withKeyValueSeparator("=") .split(forcedModList); - FMLLog.fine("System property request managing the state of %d mods", sysPropertyStateList.size()); + FMLLog.finer("System property request managing the state of %d mods", sysPropertyStateList.size()); Map modStates = Maps.newHashMap(); File forcedModFile = new File(canonicalConfigDir, "fmlModState.properties"); Properties forcedModListProperties = new Properties(); if (forcedModFile.exists() && forcedModFile.isFile()) { - FMLLog.fine("Found a mod state file %s", forcedModFile.getName()); + FMLLog.finer("Found a mod state file %s", forcedModFile.getName()); try { forcedModListProperties.load(new FileReader(forcedModFile)); - FMLLog.fine("Loaded states for %d mods from file", forcedModListProperties.size()); + FMLLog.finer("Loaded states for %d mods from file", forcedModListProperties.size()); } catch (Exception e) { diff --git a/fml/common/cpw/mods/fml/common/ModClassLoader.java b/fml/common/cpw/mods/fml/common/ModClassLoader.java index b5d8bf4ce..2b69592eb 100644 --- a/fml/common/cpw/mods/fml/common/ModClassLoader.java +++ b/fml/common/cpw/mods/fml/common/ModClassLoader.java @@ -70,7 +70,7 @@ public class ModClassLoader extends URLClassLoader } catch (URISyntaxException e) { - FMLLog.log(Level.SEVERE, "Unable to process our input to locate the minecraft code", e); + FMLLog.log(Level.SEVERE, e, "Unable to process our input to locate the minecraft code"); throw new LoaderException(e); } } diff --git a/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java b/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java index 411eb8a9a..991d48e5f 100644 --- a/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java +++ b/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java @@ -44,7 +44,7 @@ public class ModDiscoverer { if (knownLibraries.contains(minecraftSources[i].getName())) { - FMLLog.fine("Skipping known library file %s", minecraftSources[i].getAbsolutePath()); + FMLLog.finer("Skipping known library file %s", minecraftSources[i].getAbsolutePath()); } else { diff --git a/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java b/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java index 4bd09b866..a0dbfab3c 100644 --- a/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java +++ b/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java @@ -81,6 +81,8 @@ public class FMLPreInitializationEvent extends FMLStateEvent /** * Get a logger instance configured to write to the FML Log as a parent, identified by modid. Handy for mod logging! + * Configurations can be applied through the config/logging.properties file, specifying logging levels + * for your ModID. Use this! * * @return A logger */ diff --git a/fml/common/cpw/mods/fml/common/registry/GameData.java b/fml/common/cpw/mods/fml/common/registry/GameData.java index 3929d3787..551476522 100644 --- a/fml/common/cpw/mods/fml/common/registry/GameData.java +++ b/fml/common/cpw/mods/fml/common/registry/GameData.java @@ -50,13 +50,13 @@ public class GameData { ignoredMods = Maps.fromProperties(p); if (ignoredMods.size()>0) { - FMLLog.warning("Using non-empty ignored mods configuration file %s", ignoredMods.keySet()); + FMLLog.log("fml.ItemTracker", Level.WARNING, "Using non-empty ignored mods configuration file %s", ignoredMods.keySet()); } } catch (Exception e) { Throwables.propagateIfPossible(e); - FMLLog.log(Level.SEVERE, e, "Failed to read ignored ID checker mods properties file"); + FMLLog.log("fml.ItemTracker", Level.SEVERE, e, "Failed to read ignored ID checker mods properties file"); ignoredMods = ImmutableMap.of(); } } @@ -84,12 +84,12 @@ public class GameData { if (idMap.containsKey(item.field_77779_bT)) { ItemData id = idMap.get(item.field_77779_bT); - FMLLog.info("[ItemTracker] The mod %s is overwriting existing item at %d (%s from %s) with %s", mc.getModId(), id.getItemId(), id.getItemType(), id.getModId(), itemType); + FMLLog.log("fml.ItemTracker", Level.INFO, "The mod %s is overwriting existing item at %d (%s from %s) with %s", mc.getModId(), id.getItemId(), id.getItemType(), id.getModId(), itemType); } idMap.put(item.field_77779_bT, itemData); if (!"Minecraft".equals(mc.getModId())) { - FMLLog.fine("[ItemTracker] Adding item %s(%d) owned by %s", item.getClass().getName(), item.field_77779_bT, mc.getModId()); + FMLLog.log("fml.ItemTracker",Level.FINE, "Adding item %s(%d) owned by %s", item.getClass().getName(), item.field_77779_bT, mc.getModId()); } } @@ -119,12 +119,12 @@ public class GameData { Map worldMap = Maps.uniqueIndex(worldSaveItems,idMapFunction); difference = Maps.difference(worldMap, idMap); - FMLLog.fine("The difference set is %s", difference); + FMLLog.log("fml.ItemTracker", Level.FINE, "The difference set is %s", difference); if (!difference.entriesDiffering().isEmpty() || !difference.entriesOnlyOnLeft().isEmpty()) { - FMLLog.severe("FML has detected item discrepancies"); - FMLLog.severe("Missing items : %s", difference.entriesOnlyOnLeft()); - FMLLog.severe("Mismatched items : %s", difference.entriesDiffering()); + FMLLog.log("fml.ItemTracker", Level.SEVERE, "FML has detected item discrepancies"); + FMLLog.log("fml.ItemTracker", Level.SEVERE, "Missing items : %s", difference.entriesOnlyOnLeft()); + FMLLog.log("fml.ItemTracker", Level.SEVERE, "Mismatched items : %s", difference.entriesDiffering()); boolean foundNonIgnored = false; for (ItemData diff : difference.entriesOnlyOnLeft().values()) { @@ -142,7 +142,7 @@ public class GameData { } if (!foundNonIgnored) { - FMLLog.severe("FML is ignoring these ID discrepancies because of configuration. YOUR GAME WILL NOW PROBABLY CRASH. HOPEFULLY YOU WON'T HAVE CORRUPTED YOUR WORLD. BLAME %s", ignoredMods.keySet()); + FMLLog.log("fml.ItemTracker", Level.SEVERE, "FML is ignoring these ID discrepancies because of configuration. YOUR GAME WILL NOW PROBABLY CRASH. HOPEFULLY YOU WON'T HAVE CORRUPTED YOUR WORLD. BLAME %s", ignoredMods.keySet()); } isSaveValid = !foundNonIgnored; serverValidationLatch.countDown(); diff --git a/fml/common/cpw/mods/fml/common/registry/LanguageRegistry.java b/fml/common/cpw/mods/fml/common/registry/LanguageRegistry.java index ba1270e50..1de27d199 100644 --- a/fml/common/cpw/mods/fml/common/registry/LanguageRegistry.java +++ b/fml/common/cpw/mods/fml/common/registry/LanguageRegistry.java @@ -7,6 +7,7 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.logging.Level; import com.google.common.base.Charsets; @@ -142,8 +143,7 @@ public class LanguageRegistry addStringLocalization(langPack, lang); } catch (IOException e) { - FMLLog.getLogger().severe("Unable to load localization from file: " + localizationFile); - e.printStackTrace(); + FMLLog.log(Level.SEVERE, e, "Unable to load localization from file %s", localizationFile); } finally { try { @@ -152,7 +152,7 @@ public class LanguageRegistry } } catch (IOException ex) { - ex.printStackTrace(); + // HUSH } } } diff --git a/fml/common/cpw/mods/fml/relauncher/FMLRelaunchLog.java b/fml/common/cpw/mods/fml/relauncher/FMLRelaunchLog.java index 17529820f..88d85830c 100644 --- a/fml/common/cpw/mods/fml/relauncher/FMLRelaunchLog.java +++ b/fml/common/cpw/mods/fml/relauncher/FMLRelaunchLog.java @@ -2,6 +2,8 @@ package cpw.mods.fml.relauncher; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.concurrent.Executors; @@ -112,7 +114,7 @@ public class FMLRelaunchLog } /** * Our special logger for logging issues to. We copy various assets from the - * Minecraft logger to acheive a similar appearance. + * Minecraft logger to achieve a similar appearance. */ public static FMLRelaunchLog log = new FMLRelaunchLog(); @@ -124,6 +126,10 @@ public class FMLRelaunchLog private static PrintStream errCache; private Logger myLog; + private static FileHandler fileHandler; + + private static FMLLogFormatter formatter; + private FMLRelaunchLog() { } @@ -142,37 +148,66 @@ public class FMLRelaunchLog stdOut.setParent(log.myLog); Logger stdErr = Logger.getLogger("STDERR"); stdErr.setParent(log.myLog); - FMLLogFormatter formatter = new FMLLogFormatter(); - - // Console handler captures the normal stderr before it gets replaced + log.myLog.setLevel(Level.ALL); log.myLog.setUseParentHandlers(false); - log.myLog.addHandler(new ConsoleLogWrapper()); consoleLogThread = new Thread(new ConsoleLogThread()); consoleLogThread.start(); - ConsoleLogThread.wrappedHandler.setLevel(Level.parse(System.getProperty("fml.log.level","INFO"))); - ConsoleLogThread.wrappedHandler.setFormatter(formatter); - log.myLog.setLevel(Level.ALL); + formatter = new FMLLogFormatter(); try { File logPath = new File(minecraftHome, FMLRelauncher.logFileNamePattern); - FileHandler fileHandler = new FileHandler(logPath.getPath(), 0, 3); - fileHandler.setFormatter(formatter); - fileHandler.setLevel(Level.ALL); - log.myLog.addHandler(fileHandler); + fileHandler = new FileHandler(logPath.getPath(), 0, 3) + { + public synchronized void close() throws SecurityException { + // We don't want this handler to reset + } + }; } catch (Exception e) { } + resetLoggingHandlers(); + // Set system out to a log stream errCache = System.err; System.setOut(new PrintStream(new LoggingOutStream(stdOut), true)); System.setErr(new PrintStream(new LoggingOutStream(stdErr), true)); - // Reset global logging to shut up other logging sources (thanks guava!) configured = true; } + private static void resetLoggingHandlers() + { + ConsoleLogThread.wrappedHandler.setLevel(Level.parse(System.getProperty("fml.log.level","INFO"))); + // Console handler captures the normal stderr before it gets replaced + log.myLog.addHandler(new ConsoleLogWrapper()); + ConsoleLogThread.wrappedHandler.setFormatter(formatter); + fileHandler.setLevel(Level.ALL); + fileHandler.setFormatter(formatter); + log.myLog.addHandler(fileHandler); + } + + public static void loadLogConfiguration(File logConfigFile) + { + if (logConfigFile!=null && logConfigFile.exists() && logConfigFile.canRead()) + { + try + { + LogManager.getLogManager().readConfiguration(new FileInputStream(logConfigFile)); + resetLoggingHandlers(); + } + catch (Exception e) + { + log(Level.SEVERE, e, "Error reading logging configuration file %s", logConfigFile.getName()); + } + } + } + public static void log(String logChannel, Level level, String format, Object... data) + { + makeLog(logChannel); + Logger.getLogger(logChannel).log(level, String.format(format, data)); + } public static void log(Level level, String format, Object... data) { @@ -183,6 +218,12 @@ public class FMLRelaunchLog log.myLog.log(level, String.format(format, data)); } + public static void log(String logChannel, Level level, Throwable ex, String format, Object... data) + { + makeLog(logChannel); + Logger.getLogger(logChannel).log(level, String.format(format, data), ex); + } + public static void log(Level level, Throwable ex, String format, Object... data) { if (!configured) @@ -225,4 +266,9 @@ public class FMLRelaunchLog { return myLog; } + public static void makeLog(String logChannel) + { + Logger l = Logger.getLogger(logChannel); + l.setParent(log.myLog); + } }