Updated logging to log4j2

This commit is contained in:
Parker 2014-08-02 11:32:04 -04:00
parent 4e62297ab8
commit 37adec2afe
20 changed files with 81 additions and 73 deletions

View file

@ -10,7 +10,8 @@ package buildcraft.api.blueprints;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
@ -285,7 +286,7 @@ public class MappingRegistry {
} else {
// Keeping the order correct
idToBlock.add(null);
BCLog.logger.log(Level.WARNING, "Can't load block " + name);
BCLog.logger.log(Level.WARN, "Can't load block " + name);
}
}
@ -302,7 +303,7 @@ public class MappingRegistry {
} else {
// Keeping the order correct
idToItem.add(null);
BCLog.logger.log(Level.WARNING, "Can't load item " + name);
BCLog.logger.log(Level.WARN, "Can't load item " + name);
}
}
@ -325,7 +326,7 @@ public class MappingRegistry {
} else {
// Keeping the order correct
idToEntity.add(null);
BCLog.logger.log(Level.WARNING, "Can't load entity " + name);
BCLog.logger.log(Level.WARN, "Can't load entity " + name);
}
}
}

View file

@ -9,12 +9,14 @@
package buildcraft.api.core;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public final class BCLog {
public static final Logger logger = Logger.getLogger("Buildcraft");
public static final Logger logger = LogManager.getLogger("BuildCraft");
/**
* Deactivate constructor
@ -23,11 +25,9 @@ public final class BCLog {
}
public static void initLog() {
// TODO: check if the code below is still useful and remove otherwise.
//logger.setParent(FMLLog.getLogger());
logger.info("Starting BuildCraft " + getVersion());
logger.info("Copyright (c) SpaceToad, 2011");
logger.info("Copyright (c) SpaceToad, 2011-2014");
logger.info("http://www.mod-buildcraft.com");
}
@ -39,12 +39,12 @@ public final class BCLog {
msg.append(", ").append(stackTrace[0]);
}
logger.log(Level.SEVERE, msg.toString());
logger.log(Level.ERROR, msg.toString());
if (classFile != null) {
msg = new StringBuilder(mod);
msg.append(" API error: ").append(classFile.getSimpleName()).append(" is loaded from ").append(classFile.getProtectionDomain().getCodeSource().getLocation());
logger.log(Level.SEVERE, msg.toString());
logger.log(Level.ERROR, msg.toString());
}
}

View file

@ -9,7 +9,8 @@
package buildcraft.api.mj;
import java.lang.reflect.Field;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.JavaTools;
@ -36,7 +37,7 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
return JavaTools.bounds(batteryData.maxCapacity() - energyStored.getDouble(obj),
batteryData.minimumConsumption(), batteryData.maxReceivedPerCycle());
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't get energy requested", e);
BCLog.logger.log(Level.WARN, "can't get energy requested", e);
}
return 0;
}
@ -66,7 +67,7 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
return used;
}
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't add energy", e);
BCLog.logger.log(Level.WARN, "can't add energy", e);
}
return 0;
}
@ -90,7 +91,7 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
return used;
}
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't extract energy", e);
BCLog.logger.log(Level.WARN, "can't extract energy", e);
}
return 0;
}
@ -103,7 +104,7 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
try {
return energyStored.getDouble(obj);
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't get return energy stored", e);
BCLog.logger.log(Level.WARN, "can't get return energy stored", e);
return 0;
}
}
@ -116,7 +117,7 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
try {
energyStored.setDouble(obj, mj);
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't set energy stored", e);
BCLog.logger.log(Level.WARN, "can't set energy stored", e);
throw new RuntimeException(e);
}
}

View file

@ -13,7 +13,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
@ -139,10 +140,10 @@ public final class MjAPI {
obj.init(o, f.field, f.battery);
return obj;
} catch (InstantiationException e) {
BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\"");
BCLog.logger.log(Level.WARN, "can't instantiate class for energy kind \"" + kind + "\"");
return null;
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\"");
BCLog.logger.log(Level.WARN, "can't instantiate class for energy kind \"" + kind + "\"");
return null;
}
} else {
@ -191,7 +192,7 @@ public final class MjAPI {
if (!mjBatteryKinds.containsKey(kind)) {
mjBatteryKinds.put(kind, clazz);
} else {
BCLog.logger.log(Level.WARNING,
BCLog.logger.log(Level.WARN,
"energy kind \"" + kind + "\" already registered with " + clazz.getCanonicalName());
}
}

View file

@ -86,7 +86,7 @@ public class MjReconfigurator {
private ConfigurableMjBattery obtainConfigurableBattery(IBatteryObject battery) {
if (!(battery instanceof IConfigurableBatteryObject)) {
BCLog.logger.warning("Attempt to reconfigure unsupported battery: " + battery);
BCLog.logger.warn("Attempt to reconfigure unsupported battery: " + battery);
return null;
}
IConfigurableBatteryObject configurableBattery = (IConfigurableBatteryObject) battery;

View file

@ -11,7 +11,8 @@ package buildcraft;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
@ -309,7 +310,7 @@ public class BuildCraftEnergy extends BuildCraftMod {
list.add(Integer.parseInt(strippedId));
} catch (NumberFormatException ex) {
BCLog.logger.log
(Level.WARNING,
(Level.WARN,
configuration.getName() + ": Could not find biome id: "
+ strippedId + " ; Skipping!");
}
@ -332,7 +333,7 @@ public class BuildCraftEnergy extends BuildCraftMod {
if (!found) {
BCLog.logger.log
(Level.WARNING,
(Level.WARN,
configuration.getName() + ": Could not find biome id: "
+ strippedId + " ; Skipping!");
}

View file

@ -9,7 +9,8 @@
package buildcraft;
import java.util.EnumMap;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.Packet;
@ -32,7 +33,7 @@ public class BuildCraftMod {
.set(FMLOutboundHandler.OutboundTarget.ALL);
channels.get(Side.SERVER).writeOutbound(packet);
} catch (Throwable t) {
BCLog.logger.log(Level.WARNING, "sentToPlayers crash", t);
BCLog.logger.log(Level.WARN, "sentToPlayers crash", t);
}
}
@ -42,7 +43,7 @@ public class BuildCraftMod {
.set(FMLOutboundHandler.OutboundTarget.ALL);
channels.get(Side.SERVER).writeOutbound(packet);
} catch (Throwable t) {
BCLog.logger.log(Level.WARNING, "sentToPlayers crash", t);
BCLog.logger.log(Level.WARN, "sentToPlayers crash", t);
}
}
@ -59,7 +60,7 @@ public class BuildCraftMod {
name = "<no name>";
}
BCLog.logger.log(Level.WARNING, "sentToPlayer \"" + name + "\" crash", t);
BCLog.logger.log(Level.WARN, "sentToPlayer \"" + name + "\" crash", t);
}
}
@ -68,7 +69,7 @@ public class BuildCraftMod {
channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.TOSERVER);
channels.get(Side.CLIENT).writeOutbound(packet);
} catch (Throwable t) {
BCLog.logger.log(Level.WARNING, "sentToServer crash", t);
BCLog.logger.log(Level.WARN, "sentToServer crash", t);
}
}
}

View file

@ -116,7 +116,7 @@ public class Version implements Runnable {
recommendedVersion = tokens[2];
if (VERSION.matches(tokens[2])) {
BCLog.logger.finer("Using the latest version [" + getVersion() + "] for Minecraft " + mcVersion);
BCLog.logger.trace("Using the latest version [" + getVersion() + "] for Minecraft " + mcVersion);
currentVersion = EnumUpdateState.CURRENT;
return;
}
@ -124,7 +124,7 @@ public class Version implements Runnable {
}
}
BCLog.logger.warning("Using outdated version [" + VERSION + "] for Minecraft " + mcVersion
BCLog.logger.warn("Using outdated version [" + VERSION + "] for Minecraft " + mcVersion
+ ". Consider updating to " + recommendedVersion + ".");
currentVersion = EnumUpdateState.OUTDATED;
sendIMCOutdatedMessage();
@ -132,8 +132,8 @@ public class Version implements Runnable {
conn.disconnect();
reader.close();
} catch (Exception e) {
BCLog.logger.warning("Unable to read from remote version authority.");
BCLog.logger.warning(e.toString());
BCLog.logger.warn("Unable to read from remote version authority.");
BCLog.logger.warn(e.toString());
currentVersion = EnumUpdateState.CONNECTION_ERROR;
}
}
@ -187,7 +187,7 @@ public class Version implements Runnable {
} catch (Exception ex) {
ex.printStackTrace();
BCLog.logger.warning("Unable to read changelog from remote site.");
BCLog.logger.warn("Unable to read changelog from remote site.");
}
return new String[]{String.format("Unable to retrieve changelog for %s %s", DefaultProps.MOD, version)};

View file

@ -113,7 +113,7 @@ public class Blueprint extends BlueprintBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBlueprint", "readFromWorld", t);
BCLog.logger.throwing(t);
}
switch (slot.getBuildingPermission()) {

View file

@ -96,7 +96,7 @@ public abstract class BlueprintBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBase", "rotateLeft", t);
BCLog.logger.throwing(t);
}
}
}

View file

@ -11,7 +11,8 @@ package buildcraft.core.blueprints;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.TreeSet;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -267,7 +268,7 @@ public abstract class BptBuilderBase implements IAreaProvider {
item.context = getContext();
builder.getBuilders().add(item);
} catch (MappingNotFoundException e) {
BCLog.logger.log(Level.WARNING, "can't load building item", e);
BCLog.logger.log(Level.WARN, "can't load building item", e);
}
}
}

View file

@ -209,7 +209,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "checkRequirements", t);
BCLog.logger.throwing(t);
}
b.writeToWorld(context);
@ -228,7 +228,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "checkRequirements", t);
BCLog.logger.throwing(t);
}
e.writeToWorld(context);
@ -416,8 +416,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint",
"internalGetBlock", t);
BCLog.logger.throwing(t);
iterator.remove();
}
}
@ -465,7 +464,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "checkRequirements", t);
BCLog.logger.throwing(t);
}
LinkedList<ItemStack> stacksUsed = new LinkedList<ItemStack>();
@ -505,7 +504,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "checkRequirements", t);
BCLog.logger.throwing(t);
}
if (reqStk.stackSize == 0) {
@ -539,7 +538,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "useRequirements", t);
BCLog.logger.throwing(t);
}
@ -590,7 +589,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "useRequirements", t);
BCLog.logger.throwing(t);
}
if (reqStk.stackSize == 0) {
@ -622,7 +621,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "recomputeIfNeeded", t);
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
@ -651,7 +650,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "recomputeIfNeeded", t);
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
@ -713,7 +712,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing("BptBuilderBlueprint", "postProcessing", t);
BCLog.logger.throwing(t);
}
}
}

View file

@ -20,7 +20,7 @@ public class BptError extends Exception {
public BptError(String str) {
super(str);
BCLog.logger.fine("BLUEPRINT ERROR:" + str);
BCLog.logger.debug("BLUEPRINT ERROR:" + str);
}

View file

@ -8,7 +8,7 @@
*/
package buildcraft.core.utils;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
@ -80,7 +80,7 @@ public class ConfigUtils {
try {
parsed = Boolean.parseBoolean(value);
} catch (NumberFormatException ex) {
BCLog.logger.log(Level.WARNING, "Failed to parse config tag, reseting to default: " + prop.getName(), ex);
BCLog.logger.log(Level.WARN, "Failed to parse config tag, reseting to default: " + prop.getName(), ex);
prop.set(defaultValue);
return defaultValue;
}
@ -93,7 +93,7 @@ public class ConfigUtils {
try {
parsed = Integer.parseInt(value);
} catch (NumberFormatException ex) {
BCLog.logger.log(Level.WARNING, "Failed to parse config tag, reseting to default: " + prop.getName(), ex);
BCLog.logger.log(Level.WARN, "Failed to parse config tag, reseting to default: " + prop.getName(), ex);
prop.set(defaultValue);
return defaultValue;
}
@ -106,7 +106,7 @@ public class ConfigUtils {
try {
parsed = Double.parseDouble(value);
} catch (NumberFormatException ex) {
BCLog.logger.log(Level.WARNING, "Failed to parse config tag, reseting to default: " + prop.getName(), ex);
BCLog.logger.log(Level.WARN, "Failed to parse config tag, reseting to default: " + prop.getName(), ex);
prop.set(defaultValue);
return defaultValue;
}

View file

@ -66,9 +66,9 @@ public class FactoryProxyClient extends FactoryProxy {
Class<?> neiRenderer = Class.forName("codechicken.nei.DefaultOverlayRenderer");
Method method = neiRenderer.getMethod("registerGuiOverlay", Class.class, String.class, int.class, int.class);
method.invoke(null, GuiAutoCrafting.class, "crafting", 5, 11);
BCLog.logger.fine("NEI detected, adding NEI overlay");
BCLog.logger.debug("NEI detected, adding NEI overlay");
} catch (Exception e) {
BCLog.logger.fine("NEI not detected.");
BCLog.logger.debug("NEI not detected.");
}
}

View file

@ -1096,12 +1096,12 @@ public class BlockGenericPipe extends BlockBuildCraft {
if (pipe != null) {
return pipe.getConstructor(Item.class).newInstance(key);
} else {
BCLog.logger.warning("Detected pipe with unknown key (" + key + "). Did you remove a buildcraft addon?");
BCLog.logger.warn("Detected pipe with unknown key (" + key + "). Did you remove a buildcraft addon?");
}
} catch (Throwable t) {
t.printStackTrace();
BCLog.logger.warning("Failed to create pipe with (" + key + "). No valid constructor found. Possibly a item ID conflit.");
BCLog.logger.warn("Failed to create pipe with (" + key + "). No valid constructor found. Possibly a item ID conflit.");
}
return null;

View file

@ -8,7 +8,7 @@
*/
package buildcraft.transport;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
@ -75,7 +75,7 @@ public class GuiHandler implements IGuiHandler {
return null;
}
} catch (Exception ex) {
BCLog.logger.log(Level.SEVERE, "Failed to open GUI", ex);
BCLog.logger.log(Level.ERROR, "Failed to open GUI", ex);
}
return null;
}
@ -121,7 +121,7 @@ public class GuiHandler implements IGuiHandler {
return null;
}
} catch (Exception ex) {
BCLog.logger.log(Level.SEVERE, "Failed to open GUI", ex);
BCLog.logger.log(Level.ERROR, "Failed to open GUI", ex);
}
return null;
}

View file

@ -9,7 +9,8 @@
package buildcraft.transport;
import java.util.List;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -83,7 +84,7 @@ public class ItemPipe extends ItemBuildCraft implements IItemPipe {
Pipe<?> pipe = BlockGenericPipe.createPipe(this);
if (pipe == null) {
BCLog.logger.log(Level.WARNING, "Pipe failed to create during placement at {0},{1},{2}", new Object[]{i, j, k});
BCLog.logger.log(Level.WARN, "Pipe failed to create during placement at {0},{1},{2}", new Object[]{i, j, k});
return true;
}

View file

@ -12,7 +12,8 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
@ -120,7 +121,7 @@ public class PipeTransportItems extends PipeTransport {
}
if (items.size() > MAX_PIPE_STACKS) {
BCLog.logger.log(Level.WARNING, String.format("Pipe exploded at %d,%d,%d because it had too many stacks: %d", container.xCoord, container.yCoord, container.zCoord, items.size()));
BCLog.logger.log(Level.WARN, String.format("Pipe exploded at %d,%d,%d because it had too many stacks: %d", container.xCoord, container.yCoord, container.zCoord, items.size()));
destroyPipe();
return;
}
@ -134,7 +135,7 @@ public class PipeTransportItems extends PipeTransport {
}
if (numItems > MAX_PIPE_ITEMS) {
BCLog.logger.log(Level.WARNING, String.format("Pipe exploded at %d,%d,%d because it had too many items: %d", container.xCoord, container.yCoord, container.zCoord, numItems));
BCLog.logger.log(Level.WARN, String.format("Pipe exploded at %d,%d,%d because it had too many items: %d", container.xCoord, container.yCoord, container.zCoord, numItems));
destroyPipe();
}
}

View file

@ -9,7 +9,8 @@
package buildcraft.transport;
import java.util.LinkedList;
import java.util.logging.Level;
import org.apache.logging.log4j.Level;
import io.netty.buffer.ByteBuf;
@ -153,14 +154,14 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
NBTTagCompound pluggableData = nbt.getCompoundTag(key);
Class<?> pluggableClass = Class.forName(pluggableData.getString("pluggableClass"));
if (!IPipePluggable.class.isAssignableFrom(pluggableClass)) {
BCLog.logger.warning("Wrong pluggable class: " + pluggableClass);
BCLog.logger.warn("Wrong pluggable class: " + pluggableClass);
continue;
}
IPipePluggable pluggable = (IPipePluggable) pluggableClass.newInstance();
pluggable.readFromNBT(pluggableData);
pluggables[i] = pluggable;
} catch (Exception e) {
BCLog.logger.warning("Failed to load side state");
BCLog.logger.warn("Failed to load side state");
e.printStackTrace();
}
}
@ -302,7 +303,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
if (pipe != null) {
pipe.readFromNBT(nbt);
} else {
BCLog.logger.log(Level.WARNING, "Pipe failed to load from NBT at {0},{1},{2}", new Object[]{xCoord, yCoord, zCoord});
BCLog.logger.log(Level.WARN, "Pipe failed to load from NBT at {0},{1},{2}", new Object[]{xCoord, yCoord, zCoord});
deletePipe = true;
}
@ -532,7 +533,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
this.blockType = getBlockType();
if (pipe == null) {
BCLog.logger.log(Level.WARNING, "Pipe failed to initialize at {0},{1},{2}, deleting", new Object[]{xCoord, yCoord, zCoord});
BCLog.logger.log(Level.WARN, "Pipe failed to initialize at {0},{1},{2}, deleting", new Object[]{xCoord, yCoord, zCoord});
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
return;
}