Skip to content

Commit

Permalink
Improve logging on Forge
Browse files Browse the repository at this point in the history
Previously, we used the Forge Modloader logger, so messages would appear
as [FML]: [TerrainControl] (message). Now we use our own logger, so that
[TerrainControl] now replaces [FML].

However, this means that messages would appear as[TerrainControl]:
[TerrainControl] (message). The second [TerrainControl] was added by our
own logger class, as Bukkit (unlike Forge) doesn't prefix each message
with the mod name.

Now Bukkit and Forge have their own Logger implementation, and only the
Bukkit implementation adds [TerrainControl].
  • Loading branch information
rutgerkok committed Apr 15, 2016
1 parent 8175e13 commit 807ea6d
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 303 deletions.
2 changes: 0 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ repositories
dependencies
{
testCompile 'junit:junit:4+'
compile 'org.apache.logging.log4j:log4j-api:2.0-beta9'
compile 'org.apache.logging.log4j:log4j-core:2.0-beta9'
}
22 changes: 11 additions & 11 deletions common/src/main/java/com/khorn/terraincontrol/TerrainControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import com.khorn.terraincontrol.exception.InvalidConfigException;
import com.khorn.terraincontrol.generator.biome.BiomeModeManager;
import com.khorn.terraincontrol.generator.resource.Resource;
import com.khorn.terraincontrol.logging.LogMarker;
import com.khorn.terraincontrol.util.ChunkCoordinate;
import com.khorn.terraincontrol.util.minecraftTypes.DefaultMaterial;
import org.apache.logging.log4j.Marker;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -54,7 +54,7 @@ public static boolean fireCanCustomObjectSpawnEvent(CustomObject object, LocalWo

/**
* @see TerrainControlEngine#firePopulationEndEvent(LocalWorld, Random,
* boolean, int, int)
* boolean, ChunkCoordinate)
*/
public static void firePopulationEndEvent(LocalWorld world, Random random, boolean villageInChunk, ChunkCoordinate chunkCoord)
{
Expand All @@ -63,7 +63,7 @@ public static void firePopulationEndEvent(LocalWorld world, Random random, boole

/**
* @see TerrainControlEngine#firePopulationStartEvent(LocalWorld, Random,
* boolean, int, int)
* boolean, ChunkCoordinate)
*/
public static void firePopulationStartEvent(LocalWorld world, Random random, boolean villageInChunk, ChunkCoordinate chunkCoord)
{
Expand Down Expand Up @@ -186,7 +186,7 @@ public static LocalWorld getWorld(String name)
* @param messages The messages to log.
* @param level The severity of the message
*/
public static void log(Marker level, List<String> messages)
public static void log(LogMarker level, List<String> messages)
{
engine.getLogger().log(level, messages);
}
Expand All @@ -201,7 +201,7 @@ public static void log(Marker level, List<String> messages)
* @param params The parameters belonging to {0...} in the message
* string
*/
public static void log(Marker level, String message, Object... params)
public static void log(LogMarker level, String message, Object... params)
{
engine.getLogger().log(level, message, params);
}
Expand All @@ -214,7 +214,7 @@ public static void log(Marker level, String message, Object... params)
* @param ifLevel the Log level to test for
* @param messages The messages to log.
*/
public static void logIfLevel(Marker ifLevel, List<String> messages)
public static void logIfLevel(LogMarker ifLevel, List<String> messages)
{
engine.getLogger().logIfLevel(ifLevel, messages);
}
Expand All @@ -230,7 +230,7 @@ public static void logIfLevel(Marker ifLevel, List<String> messages)
* @param params The parameters belonging to {0...} in the message
* string
*/
public static void logIfLevel(Marker ifLevel, String message, Object... params)
public static void logIfLevel(LogMarker ifLevel, String message, Object... params)
{
engine.getLogger().logIfLevel(ifLevel, message, params);
}
Expand All @@ -244,7 +244,7 @@ public static void logIfLevel(Marker ifLevel, String message, Object... params)
* @param max The maximum Log level to test for
* @param messages The messages to log.
*/
public static void logIfLevel(Marker min, Marker max, List<String> messages)
public static void logIfLevel(LogMarker min, LogMarker max, List<String> messages)
{
engine.getLogger().logIfLevel(min, max, messages);
}
Expand All @@ -261,7 +261,7 @@ public static void logIfLevel(Marker min, Marker max, List<String> messages)
* @param params The parameters belonging to {0...} in the message
* string
*/
public static void logIfLevel(Marker min, Marker max, String message, Object... params)
public static void logIfLevel(LogMarker min, LogMarker max, String message, Object... params)
{
engine.getLogger().logIfLevel(min, max, message, params);
}
Expand All @@ -272,7 +272,7 @@ public static void logIfLevel(Marker min, Marker max, String message, Object...
* @param level The log level to log this stack trace at
* @param e The Throwable object to obtain stack trace information from
*/
public static void printStackTrace(Marker level, Throwable e)
public static void printStackTrace(LogMarker level, Throwable e)
{
printStackTrace(level, e, Integer.MAX_VALUE);
}
Expand All @@ -286,7 +286,7 @@ public static void printStackTrace(Marker level, Throwable e)
* from
* @param maxDepth The max number of trace elements to print
*/
public static void printStackTrace(Marker level, Throwable e, int maxDepth)
public static void printStackTrace(LogMarker level, Throwable e, int maxDepth)
{
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.khorn.terraincontrol.exception.InvalidConfigException;
import com.khorn.terraincontrol.generator.biome.BiomeModeManager;
import com.khorn.terraincontrol.generator.resource.Resource;
import com.khorn.terraincontrol.logging.LogFactory;
import com.khorn.terraincontrol.logging.Logger;
import com.khorn.terraincontrol.util.ChunkCoordinate;
import com.khorn.terraincontrol.util.minecraftTypes.DefaultMaterial;
Expand All @@ -33,14 +32,9 @@ public abstract class TerrainControlEngine
private PluginConfig pluginConfig;
private Logger logger;

public TerrainControlEngine()
public TerrainControlEngine(Logger logger)
{
logger = LogFactory.getLogger();
}

public TerrainControlEngine(org.apache.logging.log4j.Logger log4jLogger)
{
logger = LogFactory.getLogger(log4jLogger);
this.logger = logger;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import com.khorn.terraincontrol.configuration.standard.PluginStandardValues;
import com.khorn.terraincontrol.configuration.standard.WorldStandardValues;
import com.khorn.terraincontrol.logging.LogMarker;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;

import java.io.IOException;

Expand All @@ -22,37 +20,30 @@ public final class PluginConfig extends ConfigFile

public ConfigMode SettingsMode;

public static enum LogLevels
public enum LogLevels
{

Off(LogMarker.ERROR, Level.ERROR.intLevel()),
Quiet(LogMarker.WARN, Level.WARN.intLevel()),
Standard(LogMarker.INFO, Level.INFO.intLevel()),
Debug(LogMarker.DEBUG, Level.DEBUG.intLevel()),
Trace(LogMarker.TRACE, Level.TRACE.intLevel());
private final Marker marker;
private final int value;
Off(LogMarker.ERROR),
Quiet(LogMarker.WARN),
Standard(LogMarker.INFO),
Debug(LogMarker.DEBUG),
Trace(LogMarker.TRACE);
private final LogMarker marker;

private LogLevels(Marker marker, int value)
LogLevels(LogMarker marker)
{
this.marker = marker;
this.value = value;
}

public Marker getLevel()
public LogMarker getLevel()
{
return marker;
}

public int getValue()
{
return value;
}

}

public LogLevels LogLevel = LogLevels.Standard;
public String biomeConfigExtension;
private LogLevels LogLevel = LogLevels.Standard;
String biomeConfigExtension;

public PluginConfig(SettingsReader settingsReader)
{
Expand All @@ -77,10 +68,8 @@ protected void correctSettings()
if (!BiomeStandardValues.BiomeConfigExtensions.contains(this.biomeConfigExtension))
{
String newExtension = BiomeStandardValues.BIOME_CONFIG_EXTENSION.getDefaultValue();
TerrainControl.log(LogMarker.WARN, "BiomeConfig file extension {} is invalid, changing to {}", new Object[]
{
this.biomeConfigExtension, newExtension
});
TerrainControl.log(LogMarker.WARN, "BiomeConfig file extension {} is invalid, changing to {}",
this.biomeConfigExtension, newExtension);
this.biomeConfigExtension = newExtension;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,55 +1,17 @@
package com.khorn.terraincontrol.logging;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* Holds the log markers and allows to compare them to each other.
*
* <p>Markers for specific Log levels, we use these as internal Log Levels, but can
* be used to filter logs in a very specific way.</p>
*/
public class LogMarker
public enum LogMarker
{

/*
* Markers for specific Log levels, we use these as internal Log Levels, but
* can be used to filter logs in a very specific way
*/
public static final Marker FATAL = MarkerManager.getMarker("com.khorn.terraincontrol.FATAL");
public static final Marker ERROR = MarkerManager.getMarker("com.khorn.terraincontrol.ERROR", LogMarker.FATAL);
public static final Marker WARN = MarkerManager.getMarker("com.khorn.terraincontrol.WARN", LogMarker.ERROR);
public static final Marker INFO = MarkerManager.getMarker("com.khorn.terraincontrol.INFO", LogMarker.WARN);
public static final Marker DEBUG = MarkerManager.getMarker("com.khorn.terraincontrol.DEBUG", LogMarker.INFO);
public static final Marker TRACE = MarkerManager.getMarker("com.khorn.terraincontrol.TRACE", LogMarker.DEBUG);

private static Map<Marker, Integer> standardLevels = new LinkedHashMap<Marker, Integer>(6);

private LogMarker()
{
}

static
{
standardLevels.put(FATAL, Level.FATAL.intLevel());
standardLevels.put(ERROR, Level.ERROR.intLevel());
standardLevels.put(WARN, Level.WARN.intLevel());
standardLevels.put(INFO, Level.INFO.intLevel());
standardLevels.put(DEBUG, Level.DEBUG.intLevel());
standardLevels.put(TRACE, Level.TRACE.intLevel());
}

public static int compare(Marker first, Marker second)
{
Integer firstInt = standardLevels.get(first);
if (firstInt != null)
{
return standardLevels.get(first).compareTo(standardLevels.get(second));
} else
{
return 0;
}
}

FATAL,
ERROR,
WARN,
INFO,
DEBUG,
TRACE
}

This file was deleted.

Loading

0 comments on commit 807ea6d

Please sign in to comment.