Skip to content

Commit

Permalink
Fix up logging and log4j configuration (#4802)
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Mar 18, 2018
1 parent 5ace86d commit ae654ed
Show file tree
Hide file tree
Showing 29 changed files with 307 additions and 205 deletions.
4 changes: 2 additions & 2 deletions SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Identifying the Source of a Problem

You're most likely to get fast and valuable responses to your issues if you report them in the correct place. For this, you need to find the root cause of the problem.

The most important source for this information are the log files Forge creates for every run of the game. You can find them in the `logs` subdirectory of your Minecraft game directory. The most important log file is `fml-client-latest.log` for client instances (singleplayer or *connecting* to a server) and `fml-server-latest.log` for dedicated servers which contains all of Forge's and any mod's output.
The most important source for this information are the log files Forge creates for every run of the game. You can find them in the `logs` subdirectory of your Minecraft game directory. The most important log file is `latest.log` which contains all of Forge's and any mod's output for `info` of above. `debug.log` contains all the logs in `latest.log` plus the `debug` logs for more detailed debugging.

If you're faced by a crash, consult these logs files first. Near the end of the log should be a section labelled 'Minecraft Crash Report', and after it, one about `a detailed walkthrough of the error, ...`. In these sections, you'll see a bunch of lines that look like

Expand Down Expand Up @@ -108,7 +108,7 @@ If you're certain that your issue went unnoticed up until now, you can get to ac
- **Mod Version:** Just like the Forge and Minecraft version, this is crucial for quickly telling where an issue might come from. *If you're reporting an issue caused by Forge that only occurs with a certain mod installed, include this mod here. No mod version is required if it's a pure Forge bug.*
- **Complete List of Mods:** In order to reliably analyze a bug, developers need the exact same context as you do when trying to find its cause. Hence, you should always include a *full list of mods with their corresponding version* in your report. Note that you should probably only include the ones you found by [isolating the issue](#isolating-an-issue).
- **Steps to Reproduce:** You should always include a list of steps required to provoke an issue to occur. Without it, developers can only take rough guesses at what might cause the bug. Try to reduce the amount of steps to a bare minimum, to make reproducing the issue easier. If you require a sophisticated setup to get even close to the issue, you might want to consider including your save file in your report.
- **Full Log:** This is probably the most important part of your bug report. You *always* have to include the full log (`fml-client-latest.log` or `fml-server-latest.log` from earlier), since it is the only way of telling what has caused an issue in code. *Do not* paste the full log as plain text in your report, but use a site like [Pastebin](https://pastebin.com) or [GitHub Gist](https://gist.github.com) instead and link to that from your report.
- **Full Log:** This is probably the most important part of your bug report. You *always* have to include the full log (`debug.log` from earlier), since it is the only way of telling what has caused an issue in code. *Do not* paste the full log as plain text in your report, but use [GitHub Gist](https://gist.github.com) instead and link to that from your report.

### Markdown Issue Template
GitHub and BitBucket allow you to use the Markdown format for writing your issues. Below you can find a simple template that you can copy and fill in with your data. `{variables}` are written in braces and are supposed to be replaced by you with the information the variable name indicates. Everything behind two slashes (`//`) has to be interpreted as a comment and should be removed. If you want to include any link, you have to write in the `[title](url)` form. For further information on Markdown, see [this cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;

import net.minecraftforge.common.ForgeVersion;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
Expand All @@ -63,7 +64,7 @@

public class B3DModel
{
static final Logger logger = LogManager.getLogger(B3DModel.class);
static final Logger logger = LogManager.getLogger(ForgeVersion.MOD_ID + ".B3DModel");
private static final boolean printLoadedModels = "true".equals(System.getProperty("b3dloader.printLoadedModels"));
private final List<Texture> textures;
private final List<Brush> brushes;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/minecraftforge/common/ForgeVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class ForgeVersion
@SuppressWarnings("unused")
private static String target = null;

private static final Logger log = LogManager.getLogger("ForgeVersionCheck");
private static final Logger log = LogManager.getLogger(MOD_ID + ".VersionCheck");

public static int getMajorVersion()
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/minecraftforge/common/UsernameCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class UsernameCache {
private static final File saveFile = new File( /* The minecraft dir */(File) FMLInjectionData.data()[6], "usernamecache.json");
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();

private static final Logger log = LogManager.getLogger(UsernameCache.class);
private static final Logger log = LogManager.getLogger(ForgeVersion.MOD_ID + ".UsernameCache");

private UsernameCache() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ else if (tmpList != null && !skip)
}
catch (IOException e)
{
FMLLog.log.error("Error while loading config.", e);
FMLLog.log.error("Error while loading config {}.", fileName, e);
}
finally
{
Expand Down Expand Up @@ -1108,7 +1108,7 @@ public void save()
}
catch (IOException e)
{
FMLLog.log.error("Error while saving config.", e);
FMLLog.log.error("Error while saving config {}.", fileName, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ public void logMissingTextureErrors()
{
return;
}
Logger logger = LogManager.getLogger("TEXTURE ERRORS");
Logger logger = LogManager.getLogger("FML.TEXTURE_ERRORS");
logger.error(Strings.repeat("+=", 25));
logger.error("The following texture errors were found.");
Map<String,FallbackResourceManager> resManagers = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, (SimpleReloadableResourceManager)Minecraft.getMinecraft().getResourceManager(), "domainResourceManagers", "field_110548"+"_a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import net.minecraftforge.fml.common.FMLLog;
import org.apache.logging.log4j.LogManager;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected InputStream getInputStreamByName(String resourceName) throws IOExcepti
{
if ("pack.mcmeta".equals(resourceName))
{
LogManager.getLogger(container.getName()).debug("Mod {} is missing a pack.mcmeta file, substituting a dummy one", container.getName());
FMLLog.log.debug("Mod {} is missing a pack.mcmeta file, substituting a dummy one", container.getName());
return new ByteArrayInputStream(("{\n" +
" \"pack\": {\n"+
" \"description\": \"dummy FML pack for "+container.getName()+"\",\n"+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import net.minecraftforge.fml.common.FMLLog;
import org.apache.logging.log4j.LogManager;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -64,7 +65,7 @@ protected InputStream getInputStreamByName(String resourceName) throws IOExcepti
{
if ("pack.mcmeta".equals(resourceName))
{
LogManager.getLogger(container.getName()).debug("Mod {} is missing a pack.mcmeta file, substituting a dummy one", container.getName());
FMLLog.log.debug("Mod {} is missing a pack.mcmeta file, substituting a dummy one", container.getName());
return new ByteArrayInputStream(("{\n" +
" \"pack\": {\n"+
" \"description\": \"dummy FML pack for "+container.getName()+"\",\n"+
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/minecraftforge/fml/client/GuiErrorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class GuiErrorBase extends GuiErrorScreen
{
static final File minecraftDir = new File(Loader.instance().getConfigDir().getParent());
static final File clientLog = new File(minecraftDir, "logs/fml-client-latest.log");
static final File logFile = new File(minecraftDir, "logs/latest.log");
public GuiErrorBase()
{
super(null, null);
Expand All @@ -48,7 +48,7 @@ public void initGui()
super.initGui();
this.buttonList.clear();
this.buttonList.add(new GuiButton(10, 50, this.height - 38, this.width / 2 - 55, 20, translateOrDefault("fml.button.open.mods.folder", "Open Mods Folder")));
String openFileText = translateOrDefault("fml.button.open.file", "Open %s", clientLog.getName());
String openFileText = translateOrDefault("fml.button.open.file", "Open %s", logFile.getName());
this.buttonList.add(new GuiButton(11, this.width / 2 + 5, this.height - 38, this.width / 2 - 55, 20, openFileText));
}

Expand All @@ -71,11 +71,11 @@ else if (button.id == 11)
{
try
{
Desktop.getDesktop().open(clientLog);
Desktop.getDesktop().open(logFile);
}
catch (Exception e)
{
FMLLog.log.error("Problem opening log file {}", clientLog, e);
FMLLog.log.error("Problem opening log file {}", logFile, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks)
this.drawCenteredString(this.fontRenderer, String.format(TextFormatting.BOLD + "%s" + TextFormatting.RESET + " : %s", v.getLabel(), v.getRangeString()), this.width / 2, offset, 0xEEEEEE);
}
offset+=20;
String seeLogText = I18n.format("fml.messages.mod.missing.dependencies.see.log", GuiErrorBase.clientLog.getName());
String seeLogText = I18n.format("fml.messages.mod.missing.dependencies.see.log", GuiErrorBase.logFile.getName());
this.drawCenteredString(this.fontRenderer, seeLogText, this.width / 2, offset, 0xFFFFFF);
super.drawScreen(mouseX, mouseY, partialTicks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks)
offset+=15;
this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.wrongminecraft.fix", wrongMC.mod.getName()),this.width/2, offset, 0xFFFFFF);
offset+=20;
this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.missing.dependencies.see.log", GuiErrorBase.clientLog.getName()), this.width / 2, offset, 0xFFFFFF);
this.drawCenteredString(this.fontRenderer, I18n.format("fml.messages.mod.missing.dependencies.see.log", GuiErrorBase.logFile.getName()), this.width / 2, offset, 0xFFFFFF);
super.drawScreen(mouseX, mouseY, partialTicks);
}
}
7 changes: 5 additions & 2 deletions src/main/java/net/minecraftforge/fml/common/FMLContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
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;

Expand All @@ -60,6 +61,8 @@
*/
public final class FMLContainer extends DummyModContainer implements WorldAccessContainer
{
private static final Logger modTrackerLogger = LogManager.getLogger("FML.ModTracker");

public FMLContainer()
{
super(new ModMetadata());
Expand Down Expand Up @@ -190,12 +193,12 @@ public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> p
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());
}
}
}
Expand Down
20 changes: 2 additions & 18 deletions src/main/java/net/minecraftforge/fml/common/FMLLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading

0 comments on commit ae654ed

Please sign in to comment.