Logging overhaul

This commit is contained in:
Nicholas Ignoffo 2018-02-16 23:48:28 -08:00
parent 29c2ebe8c2
commit b29ade63f0
12 changed files with 130 additions and 40 deletions

View file

@ -11,6 +11,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID) @Mod.EventBusSubscriber(modid = BloodMagic.MODID)
public class ConfigHandler { public class ConfigHandler {
@Config.Comment({"General settings"})
public static ConfigGeneral general = new ConfigGeneral();
@Config.Comment({"Blacklist options for various features"}) @Config.Comment({"Blacklist options for various features"})
public static ConfigBlacklist blacklist = new ConfigBlacklist(); public static ConfigBlacklist blacklist = new ConfigBlacklist();
@Config.Comment({"Value modifiers for various features"}) @Config.Comment({"Value modifiers for various features"})
@ -30,6 +32,13 @@ public class ConfigHandler {
} }
} }
public static class ConfigGeneral {
@Config.Comment({"Enables extra information to be printed to the log.", "Warning: May drastically increase log size."})
public boolean enableDebugLogging = false;
@Config.Comment({"Enables extra information to be printed to the log.", "Warning: May drastically increase log size."})
public boolean enableAPILogging = false;
}
public static class ConfigBlacklist { public static class ConfigBlacklist {
@Config.Comment({"Stops listed blocks and entities from being teleposed.", "Use the registry name of the block or entity. Vanilla objects do not require the modid.", "If a block is specified, you can list the variants to only blacklist a given state."}) @Config.Comment({"Stops listed blocks and entities from being teleposed.", "Use the registry name of the block or entity. Vanilla objects do not require the modid.", "If a block is specified, you can list the variants to only blacklist a given state."})
public String[] teleposer = {"bedrock", "mob_spawner"}; public String[] teleposer = {"bedrock", "mob_spawner"};

View file

@ -2,6 +2,7 @@ package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.IBloodMagicAPI; import WayofTime.bloodmagic.api.IBloodMagicAPI;
import WayofTime.bloodmagic.altar.EnumAltarComponent; import WayofTime.bloodmagic.altar.EnumAltarComponent;
import WayofTime.bloodmagic.util.BMLog;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -45,7 +46,7 @@ public class BloodMagicAPI implements IBloodMagicAPI {
@Override @Override
public void registerAltarComponent(@Nonnull IBlockState state, @Nonnull String componentType) { public void registerAltarComponent(@Nonnull IBlockState state, @Nonnull String componentType) {
EnumAltarComponent component = EnumAltarComponent.NOTAIR; EnumAltarComponent component = null;
for (EnumAltarComponent type : EnumAltarComponent.VALUES) { for (EnumAltarComponent type : EnumAltarComponent.VALUES) {
if (type.name().equalsIgnoreCase(componentType)) { if (type.name().equalsIgnoreCase(componentType)) {
component = type; component = type;
@ -53,7 +54,10 @@ public class BloodMagicAPI implements IBloodMagicAPI {
} }
} }
altarComponents.put(component, state); if (component != null) {
BMLog.API.info("Registered {} as a {} altar component.", state, componentType);
altarComponents.put(component, state);
} else BMLog.API.warn("Invalid Altar component type: {}.", componentType);
} }
@Nonnull @Nonnull

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.api.impl; package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.IBloodMagicBlacklist; import WayofTime.bloodmagic.api.IBloodMagicBlacklist;
import WayofTime.bloodmagic.util.BMLog;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -28,8 +29,10 @@ public class BloodMagicBlacklist implements IBloodMagicBlacklist {
@Override @Override
public void addTeleposer(@Nonnull IBlockState state) { public void addTeleposer(@Nonnull IBlockState state) {
if (!teleposer.contains(state)) if (!teleposer.contains(state)) {
BMLog.API.info("Blacklist: Added {} to the Teleposer blacklist.", state);
teleposer.add(state); teleposer.add(state);
}
} }
public void addTeleposer(@Nonnull Block block) { public void addTeleposer(@Nonnull Block block) {
@ -39,14 +42,18 @@ public class BloodMagicBlacklist implements IBloodMagicBlacklist {
@Override @Override
public void addTeleposer(@Nonnull ResourceLocation entityId) { public void addTeleposer(@Nonnull ResourceLocation entityId) {
if (!teleposerEntities.contains(entityId)) if (!teleposerEntities.contains(entityId)) {
BMLog.API.info("Blacklist: Added {} to the Teleposer blacklist.", entityId);
teleposerEntities.add(entityId); teleposerEntities.add(entityId);
}
} }
@Override @Override
public void addTransposition(@Nonnull IBlockState state) { public void addTransposition(@Nonnull IBlockState state) {
if (!transposition.contains(state)) if (!transposition.contains(state)) {
BMLog.API.info("Blacklist: Added {} to the Transposition blacklist.", state);
transposition.add(state); transposition.add(state);
}
} }
public void addTransposition(@Nonnull Block block) { public void addTransposition(@Nonnull Block block) {
@ -56,8 +63,10 @@ public class BloodMagicBlacklist implements IBloodMagicBlacklist {
@Override @Override
public void addGreenGrove(@Nonnull IBlockState state) { public void addGreenGrove(@Nonnull IBlockState state) {
if (!greenGrove.contains(state)) if (!greenGrove.contains(state)) {
BMLog.API.info("Blacklist: Added {} to the Green Grove blacklist.", state);
greenGrove.add(state); greenGrove.add(state);
}
} }
public void addGreenGrove(@Nonnull Block block) { public void addGreenGrove(@Nonnull Block block) {
@ -67,8 +76,10 @@ public class BloodMagicBlacklist implements IBloodMagicBlacklist {
@Override @Override
public void addWellOfSuffering(@Nonnull ResourceLocation entityId) { public void addWellOfSuffering(@Nonnull ResourceLocation entityId) {
if (!sacrifice.contains(entityId)) if (!sacrifice.contains(entityId)) {
BMLog.API.info("Blacklist: Added {} to the Well of Suffering blacklist.", entityId);
sacrifice.add(entityId); sacrifice.add(entityId);
}
} }
// Internal use getters // Internal use getters

View file

@ -3,6 +3,7 @@ package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.IBloodMagicValueManager; import WayofTime.bloodmagic.api.IBloodMagicValueManager;
import WayofTime.bloodmagic.incense.EnumTranquilityType; import WayofTime.bloodmagic.incense.EnumTranquilityType;
import WayofTime.bloodmagic.incense.TranquilityStack; import WayofTime.bloodmagic.incense.TranquilityStack;
import WayofTime.bloodmagic.util.BMLog;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -24,6 +25,7 @@ public class BloodMagicValueManager implements IBloodMagicValueManager {
@Override @Override
public void setSacrificialValue(@Nonnull ResourceLocation entityId, int value) { public void setSacrificialValue(@Nonnull ResourceLocation entityId, int value) {
BMLog.API.info("Value Manager: Set sacrificial value of {} to {}.", entityId, value);
sacrificial.put(entityId, value); sacrificial.put(entityId, value);
} }
@ -37,13 +39,17 @@ public class BloodMagicValueManager implements IBloodMagicValueManager {
} }
} }
if (tranquility != null) if (tranquility != null) {
BMLog.API.info("Value Manager: Set tranquility value of {} to {} @ {}", state, tranquilityType, value);
this.tranquility.put(state, new TranquilityStack(tranquility, value)); this.tranquility.put(state, new TranquilityStack(tranquility, value));
} else BMLog.API.warn("Invalid tranquility type: {}.", tranquilityType);
} }
public void setTranquility(Block block, TranquilityStack tranquilityStack) { public void setTranquility(Block block, TranquilityStack tranquilityStack) {
for (IBlockState state : block.getBlockState().getValidStates()) for (IBlockState state : block.getBlockState().getValidStates()) {
BMLog.API.info("Value Manager: Set tranquility value of {} to {} @ {}", state, tranquilityStack.type, tranquilityStack.value);
tranquility.put(state, tranquilityStack); tranquility.put(state, tranquilityStack);
}
} }
public Map<ResourceLocation, Integer> getSacrificial() { public Map<ResourceLocation, Integer> getSacrificial() {

View file

@ -1,5 +1,7 @@
package WayofTime.bloodmagic.core.data; package WayofTime.bloodmagic.core.data;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.BMLog;
import WayofTime.bloodmagic.util.PleaseStopUsingMe; import WayofTime.bloodmagic.util.PleaseStopUsingMe;
import WayofTime.bloodmagic.event.AddToNetworkEvent; import WayofTime.bloodmagic.event.AddToNetworkEvent;
import WayofTime.bloodmagic.event.SoulNetworkEvent; import WayofTime.bloodmagic.event.SoulNetworkEvent;
@ -130,7 +132,7 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
if (getParent() != null) if (getParent() != null)
getParent().markDirty(); getParent().markDirty();
else else
PleaseStopUsingMe.logger.error("A SoulNetwork was created, but a parent was not set to allow saving."); BMLog.DEFAULT.error("A SoulNetwork was created, but a parent was not set to allow saving.");
} }
@Nullable @Nullable

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.core.registry; package WayofTime.bloodmagic.core.registry;
import WayofTime.bloodmagic.util.PleaseStopUsingMe; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.BMLog;
import WayofTime.bloodmagic.util.ItemStackWrapper; import WayofTime.bloodmagic.util.ItemStackWrapper;
import WayofTime.bloodmagic.altar.EnumAltarTier; import WayofTime.bloodmagic.altar.EnumAltarTier;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
@ -29,7 +30,7 @@ public class AltarRecipeRegistry {
if (!recipes.containsValue(altarRecipe) && altarRecipe.getInput().size() > 0) if (!recipes.containsValue(altarRecipe) && altarRecipe.getInput().size() > 0)
recipes.put(altarRecipe.getInput(), altarRecipe); recipes.put(altarRecipe.getInput(), altarRecipe);
else else
PleaseStopUsingMe.logger.error("Error adding altar recipe for input [{}].", altarRecipe.toString()); BMLog.DEFAULT.error("Error adding altar recipe for input [{}].", altarRecipe.toString());
} }
public static void registerFillRecipe(ItemStack orbStack, EnumAltarTier tier, int maxForOrb, int consumeRate, int drainRate) { public static void registerFillRecipe(ItemStack orbStack, EnumAltarTier tier, int maxForOrb, int consumeRate, int drainRate) {

View file

@ -1,7 +1,8 @@
package WayofTime.bloodmagic.core.registry; package WayofTime.bloodmagic.core.registry;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.BMLog;
import WayofTime.bloodmagic.util.BlockStack; import WayofTime.bloodmagic.util.BlockStack;
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
import WayofTime.bloodmagic.ritual.data.imperfect.ImperfectRitual; import WayofTime.bloodmagic.ritual.data.imperfect.ImperfectRitual;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
@ -23,7 +24,7 @@ public class ImperfectRitualRegistry {
public static void registerRitual(ImperfectRitual imperfectRitual, String id, boolean enabled) { public static void registerRitual(ImperfectRitual imperfectRitual, String id, boolean enabled) {
if (imperfectRitual != null) { if (imperfectRitual != null) {
if (registry.containsKey(id)) if (registry.containsKey(id))
PleaseStopUsingMe.logger.error("Duplicate imperfect ritual id: %s", id); BMLog.DEFAULT.error("Duplicate imperfect ritual id: %s", id);
else { else {
registry.put(id, imperfectRitual); registry.put(id, imperfectRitual);
enabledRituals.put(imperfectRitual, enabled); enabledRituals.put(imperfectRitual, enabled);
@ -71,7 +72,7 @@ public class ImperfectRitualRegistry {
try { try {
return enabledRituals.get(imperfectRitual); return enabledRituals.get(imperfectRitual);
} catch (NullPointerException e) { } catch (NullPointerException e) {
PleaseStopUsingMe.logger.error("Invalid Imperfect Ritual was called"); BMLog.DEFAULT.error("Invalid Imperfect Ritual was called");
return false; return false;
} }
} }

View file

@ -1,7 +1,7 @@
package WayofTime.bloodmagic.core.registry; package WayofTime.bloodmagic.core.registry;
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
import WayofTime.bloodmagic.ritual.data.Ritual; import WayofTime.bloodmagic.ritual.data.Ritual;
import WayofTime.bloodmagic.util.BMLog;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
@ -28,14 +28,14 @@ public class RitualRegistry {
*/ */
public static void registerRitual(Ritual ritual, String id, boolean enabled) { public static void registerRitual(Ritual ritual, String id, boolean enabled) {
if (locked) { if (locked) {
PleaseStopUsingMe.logger.error("This registry has been locked. Please register your ritual earlier."); BMLog.DEFAULT.error("This registry has been locked. Please register your ritual earlier.");
PleaseStopUsingMe.logger.error("If you reflect this, I will hunt you down. - TehNut"); BMLog.DEFAULT.error("If you reflect this, I will hunt you down. - TehNut");
return; return;
} }
if (ritual != null) { if (ritual != null) {
if (registry.containsKey(id)) if (registry.containsKey(id))
PleaseStopUsingMe.logger.error("Duplicate ritual id: %s", id); BMLog.DEFAULT.error("Duplicate ritual id: %s", id);
else { else {
registry.put(id, ritual); registry.put(id, ritual);
enabledRituals.put(ritual, enabled); enabledRituals.put(ritual, enabled);
@ -78,7 +78,7 @@ public class RitualRegistry {
try { try {
return enabledRituals.get(ritual); return enabledRituals.get(ritual);
} catch (NullPointerException e) { } catch (NullPointerException e) {
PleaseStopUsingMe.logger.error("Invalid Ritual was called"); BMLog.DEFAULT.error("Invalid Ritual was called");
return false; return false;
} }
} }
@ -111,13 +111,10 @@ public class RitualRegistry {
locked = true; // Lock registry so no no rituals can be registered locked = true; // Lock registry so no no rituals can be registered
lookupList.clear(); // Make sure it's empty lookupList.clear(); // Make sure it's empty
lookupList.addAll(registry.keySet()); lookupList.addAll(registry.keySet());
Collections.sort(lookupList, new Comparator<String>() { Collections.sort(lookupList, (o1, o2) -> {
@Override Ritual ritual1 = registry.get(o1);
public int compare(String o1, String o2) { Ritual ritual2 = registry.get(o2);
Ritual ritual1 = registry.get(o1); return ritual1.getComponents().size() > ritual2.getComponents().size() ? -1 : 0; // Put earlier if bigger
Ritual ritual2 = registry.get(o2);
return ritual1.getComponents().size() > ritual2.getComponents().size() ? -1 : 0; // Put earlier if bigger
}
}); });
} }
} }

View file

@ -1,8 +1,9 @@
package WayofTime.bloodmagic.demonAura; package WayofTime.bloodmagic.demonAura;
import WayofTime.bloodmagic.util.PleaseStopUsingMe; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.soul.DemonWillHolder; import WayofTime.bloodmagic.soul.DemonWillHolder;
import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.soul.EnumDemonWillType;
import WayofTime.bloodmagic.util.BMLog;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
@ -45,13 +46,13 @@ public class WorldDemonWillHandler {
public static void addWillWorld(int dim) { public static void addWillWorld(int dim) {
if (!containedWills.containsKey(dim)) { if (!containedWills.containsKey(dim)) {
containedWills.put(dim, new WillWorld(dim)); containedWills.put(dim, new WillWorld(dim));
PleaseStopUsingMe.logger.info("Creating demon will cache for world " + dim); BMLog.DEBUG.info("Creating demon will cache for world " + dim);
} }
} }
public static void removeWillWorld(int dim) { public static void removeWillWorld(int dim) {
containedWills.remove(dim); containedWills.remove(dim);
PleaseStopUsingMe.logger.info("Removing demon will cache for world " + dim); BMLog.DEBUG.info("Removing demon will cache for world " + dim);
} }
public static void addWillChunk(int dim, Chunk chunk, short base, DemonWillHolder currentWill) { public static void addWillChunk(int dim, Chunk chunk, short base, DemonWillHolder currentWill) {

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.livingArmour; package WayofTime.bloodmagic.livingArmour;
import WayofTime.bloodmagic.util.PleaseStopUsingMe; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.BMLog;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -31,7 +32,7 @@ public class LivingArmourHandler {
try { try {
Constructor<? extends LivingArmourUpgrade> ctor = clazz.getConstructor(int.class); Constructor<? extends LivingArmourUpgrade> ctor = clazz.getConstructor(int.class);
if (ctor == null) { if (ctor == null) {
PleaseStopUsingMe.logger.error("Error adding living armour upgrade {} as it doesn't have a valid constructor.", upgrade.getUniqueIdentifier()); BMLog.DEFAULT.error("Error adding living armour upgrade {} as it doesn't have a valid constructor.", upgrade.getUniqueIdentifier());
} else { } else {
upgradeConstructorMap.put(upgrade.getUniqueIdentifier(), ctor); upgradeConstructorMap.put(upgrade.getUniqueIdentifier(), ctor);
} }

View file

@ -1,8 +1,8 @@
package WayofTime.bloodmagic.ritual.portal; package WayofTime.bloodmagic.ritual.portal;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
import WayofTime.bloodmagic.teleport.PortalLocation; import WayofTime.bloodmagic.teleport.PortalLocation;
import WayofTime.bloodmagic.util.BMLog;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
import java.io.*; import java.io.*;
@ -27,12 +27,12 @@ public class LocationsHandler implements Serializable {
updateFile(fileName, portals); updateFile(fileName, portals);
} }
if (!portals.get(name).isEmpty() && portals.get(name).size() >= 2) { if (!portals.get(name).isEmpty() && portals.get(name).size() >= 2) {
PleaseStopUsingMe.logger.info("Location " + name + " already exists."); BMLog.DEBUG.info("Location {} already exists.", name);
updateFile(fileName, portals); updateFile(fileName, portals);
return false; return false;
} else { } else {
portals.get(name).add(location); portals.get(name).add(location);
PleaseStopUsingMe.logger.info("Adding " + name); BMLog.DEBUG.info("Adding {}", name);
updateFile(fileName, portals); updateFile(fileName, portals);
return true; return true;
} }
@ -42,11 +42,11 @@ public class LocationsHandler implements Serializable {
if (portals.get(name) != null && !portals.get(name).isEmpty()) { if (portals.get(name) != null && !portals.get(name).isEmpty()) {
if (portals.get(name).contains(location)) { if (portals.get(name).contains(location)) {
portals.get(name).remove(location); portals.get(name).remove(location);
PleaseStopUsingMe.logger.info("Removing " + name); BMLog.DEBUG.info("Removing {}", name);
updateFile(fileName, portals); updateFile(fileName, portals);
return true; return true;
} else { } else {
PleaseStopUsingMe.logger.info("No location matching " + name); BMLog.DEBUG.info("No location matching {}", name);
updateFile(fileName, portals); updateFile(fileName, portals);
return false; return false;
} }
@ -75,10 +75,10 @@ public class LocationsHandler implements Serializable {
if (!file.exists()) { if (!file.exists()) {
if (file.getParentFile().mkdir()) { if (file.getParentFile().mkdir()) {
if (file.createNewFile()) { if (file.createNewFile()) {
PleaseStopUsingMe.logger.info("Creating " + fileName + " in " + String.valueOf(DimensionManager.getCurrentSaveRootDirectory())); BMLog.DEBUG.info("Creating {} in {}", fileName, DimensionManager.getCurrentSaveRootDirectory());
} }
} else if (file.createNewFile()) { } else if (file.createNewFile()) {
PleaseStopUsingMe.logger.info("Creating " + fileName + " in " + String.valueOf(DimensionManager.getCurrentSaveRootDirectory())); BMLog.DEBUG.info("Creating {} in {}", fileName, DimensionManager.getCurrentSaveRootDirectory());
} }
} }
FileInputStream fileIn = new FileInputStream(file); FileInputStream fileIn = new FileInputStream(file);
@ -90,7 +90,7 @@ public class LocationsHandler implements Serializable {
} catch (IOException e) { } catch (IOException e) {
return null; return null;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
PleaseStopUsingMe.logger.error(String.valueOf(file) + " was not found in " + String.valueOf(DimensionManager.getCurrentSaveRootDirectory())); BMLog.DEFAULT.error("{} was not found in {}", file, DimensionManager.getCurrentSaveRootDirectory());
return null; return null;
} }
} }

View file

@ -0,0 +1,57 @@
package WayofTime.bloodmagic.util;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.ConfigHandler;
import org.apache.commons.lang3.text.WordUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public enum BMLog {
DEFAULT(BloodMagic.MODID) {
@Override
boolean enabled() {
return true;
}
},
DEBUG() {
@Override
boolean enabled() {
return ConfigHandler.general.enableDebugLogging;
}
},
API() {
@Override
boolean enabled() {
return ConfigHandler.general.enableAPILogging;
}
},
;
private final Logger logger;
BMLog(String logName) {
logger = LogManager.getLogger(logName);
}
BMLog() {
logger = LogManager.getLogger(BloodMagic.MODID + "|" + WordUtils.capitalizeFully(name().replace("_", " ")));
}
abstract boolean enabled();
public void info(String input, Object... args) {
if (enabled())
logger.info(input, args);
}
public void error(String input, Object... args) {
if (enabled())
logger.error(input, args);
}
public void warn(String input, Object... args) {
if (enabled())
logger.warn(input, args);
}
}