Better logger support

This commit is contained in:
MattBDev
2020-10-06 14:44:33 -04:00
parent 96dcb95b7c
commit f5a42c63a7
27 changed files with 124 additions and 114 deletions

View File

@ -14,10 +14,6 @@ import com.boydti.fawe.util.TextureUtil;
import com.boydti.fawe.util.WEManager;
import com.github.luben.zstd.util.Native;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -120,40 +116,6 @@ public class Fawe {
instance = new Fawe(implementation);
}
public static void debugPlain(String s) {
if (instance != null) {
instance.implementation.debug(s);
} else {
log.debug(s);
}
}
/**
* Write something to the console.
*/
public static void debug(String s) {
Actor actor = Request.request().getActor();
if (actor != null && actor.isPlayer()) {
actor.printInfo(TextComponent.of(s));
return;
}
debugPlain(s);
}
/**
* Write something to the console.
*
* @param c The Component to be printed
*/
public static void debug(Component c) {
Actor actor = Request.request().getActor();
if (actor != null && actor.isPlayer()) {
actor.printDebug(c);
return;
}
debugPlain(c.toString());
}
/**
* The platform specific implementation.
*/
@ -311,7 +273,7 @@ public class Fawe {
Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL = Math.min(6, Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL);
Settings.IMP.HISTORY.COMPRESSION_LEVEL = Math.min(6, Settings.IMP.HISTORY.COMPRESSION_LEVEL);
log.error("ZSTD Compression Binding Not Found.\n"
+ "FAWE will still work but compression won't work as well.\n", e);
+ "FAWE will still work but compression won't work as well.\n", e);
}
}
try {
@ -326,9 +288,7 @@ public class Fawe {
boolean x86OS = System.getProperty("sun.arch.data.model").contains("32");
boolean x86JVM = System.getProperty("os.arch").contains("32");
if (x86OS != x86JVM) {
debug("====== UPGRADE TO 64-BIT JAVA ======");
debug("You are running 32-bit Java on a 64-bit machine");
debug("====================================");
log.info("You are running 32-bit Java on a 64-bit machine. Please upgrade to 64-bit Java.");
}
}
@ -362,11 +322,9 @@ public class Fawe {
}
}
} catch (Throwable ignored) {
debug("====== MEMORY LISTENER ERROR ======");
debug("FAWE needs access to the JVM memory system:");
debug(" - Change your Java security settings");
debug(" - Disable this with `max-memory-percent: -1`");
debug("===================================");
log.error("FAWE encountered an error trying to listen to JVM memory.\n"
+ "Please change your Java security settings or disable this message by"
+ "changing 'max-memory-percent' in the config files to '-1'.");
}
}

View File

@ -56,6 +56,7 @@ import java.util.function.Function;
import java.util.function.Supplier;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
public enum FaweCache implements Trimable {
IMP
@ -502,7 +503,7 @@ public enum FaweCache implements Trimable {
} else if (value instanceof Boolean) {
return asTag((byte) ((boolean) value ? 1 : 0));
}
System.out.println("Invalid nbt: " + value);
getLogger(FaweCache.class).error("Invalid nbt: {}", value);
return null;
}

View File

@ -13,8 +13,6 @@ import java.util.UUID;
public interface IFawe {
void debug(final String s);
File getDirectory();
TaskManager getTaskManager();

View File

@ -1,6 +1,5 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.implementation.processors.EmptyBatchProcessor;
import com.boydti.fawe.beta.implementation.processors.MultiBatchProcessor;
@ -14,6 +13,8 @@ import java.util.Set;
import java.util.concurrent.Future;
import java.util.function.Function;
import static org.slf4j.LoggerFactory.getLogger;
public interface IBatchProcessor {
/**
@ -79,9 +80,7 @@ public interface IBatchProcessor {
layer++;
}
} catch (ArrayIndexOutOfBoundsException exception) {
Fawe.imp().debug("minY = " + minY);
Fawe.imp().debug("layer = " + ((minY - 15) >> 4));
exception.printStackTrace();
getLogger(IBatchProcessor.class).error("minY = {} , layer = {}", minY, ((minY - 15) >> 4), exception);
}
return false;
}

View File

@ -6,9 +6,13 @@ import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.jetbrains.annotations.Range;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class CharBlocks implements IBlocks {
public static final Logger logger = LoggerFactory.getLogger(CharBlocks.class);
public static final Section FULL = new Section() {
@Override
public final char[] get(CharBlocks blocks, int layer) {
@ -17,7 +21,7 @@ public abstract class CharBlocks implements IBlocks {
};
public static final Section EMPTY = new Section() {
@Override
public synchronized final char[] get(CharBlocks blocks, int layer) {
public final synchronized char[] get(CharBlocks blocks, int layer) {
char[] arr = blocks.blocks[layer];
if (arr == null) {
arr = blocks.blocks[layer] = blocks.update(layer, null);
@ -120,10 +124,9 @@ public abstract class CharBlocks implements IBlocks {
try {
set(layer, index, value);
} catch (ArrayIndexOutOfBoundsException exception) {
logger.error("Tried setting block at coordinates (" + x + "," + y + "," + z + ")");
assert Fawe.imp() != null;
Fawe.imp().debug("Tried Setting Block at x:" + x + ", y:" + y + " , z:" + z);
Fawe.imp().debug("Layer variable was = " + layer);
exception.printStackTrace();
logger.error("Layer variable was = {}", layer, exception);
}
}

View File

@ -30,7 +30,7 @@ public class YamlConfiguration extends FileConfiguration {
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
/**
* Creates a new {@link com.boydti.fawe.configuration.file.YamlConfiguration}, loading from the given file.
* Creates a new {@link YamlConfiguration}, loading from the given file.
*
* <p>
* Any errors loading the Configuration will be logged and then ignored.
@ -46,12 +46,12 @@ public class YamlConfiguration extends FileConfiguration {
* @return Resulting configuration
* @throws IllegalArgumentException Thrown if file is null
*/
public static com.boydti.fawe.configuration.file.YamlConfiguration loadConfiguration(final File file) {
public static YamlConfiguration loadConfiguration(final File file) {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
final com.boydti.fawe.configuration.file.YamlConfiguration config = new com.boydti.fawe.configuration.file.YamlConfiguration();
final YamlConfiguration config = new YamlConfiguration();
try {
config.load(file);
@ -64,11 +64,8 @@ public class YamlConfiguration extends FileConfiguration {
dest = new File(file.getAbsolutePath() + "_broken_" + i++);
}
Files.copy(file.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
System.out.println("&dCould not read: &7" + file);
System.out.println("&dRenamed to: &7" + dest.getName());
System.out.println("&c============ Full stacktrace ============");
ex.printStackTrace();
System.out.println("&c=========================================");
getLogger(YamlConfiguration.class).error("Could not read: {}\n"
+ "Renamed to: {}", file, dest.getName(), ex);
} catch (final IOException e) {
e.printStackTrace();
}
@ -78,7 +75,7 @@ public class YamlConfiguration extends FileConfiguration {
}
/**
* Creates a new {@link com.boydti.fawe.configuration.file.YamlConfiguration}, loading from the given reader.
* Creates a new {@link YamlConfiguration}, loading from the given reader.
*
* <p>
* Any errors loading the Configuration will be logged and then ignored.
@ -90,12 +87,12 @@ public class YamlConfiguration extends FileConfiguration {
* @return resulting configuration
* @throws IllegalArgumentException Thrown if stream is null
*/
public static com.boydti.fawe.configuration.file.YamlConfiguration loadConfiguration(final Reader reader) {
public static YamlConfiguration loadConfiguration(final Reader reader) {
if (reader == null) {
throw new NullPointerException("Reader cannot be null");
}
final com.boydti.fawe.configuration.file.YamlConfiguration config = new com.boydti.fawe.configuration.file.YamlConfiguration();
final YamlConfiguration config = new YamlConfiguration();
try {
config.load(reader);

View File

@ -44,6 +44,8 @@ import java.util.UUID;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
import static org.slf4j.LoggerFactory.getLogger;
public class MCAChunk implements IChunk {
public final boolean[] hasSections = new boolean[16];
@ -308,7 +310,7 @@ public class MCAChunk implements IChunk {
Object value = state.getState(property);
String valueStr = value.toString();
if (Character.isUpperCase(valueStr.charAt(0))) {
System.out.println("Invalid uppercase value " + value);
getLogger(MCAChunk.class).warn("Invalid uppercase value {}", value);
valueStr = valueStr.toLowerCase(Locale.ROOT);
}
out.writeNamedTag(key, valueStr);

View File

@ -272,7 +272,7 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, ICh
try (NBTInputStream nis = getChunkIS(offset)) {
chunk.read(nis, false);
}
System.out.println("TODO multithreaded"); // TODO
//TODO multithreaded
return chunk;
}

View File

@ -6,6 +6,8 @@ import com.sk89q.jnbt.NBTInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import static org.slf4j.LoggerFactory.getLogger;
public class StreamDelegate {
private static final byte[][] ZERO_KEYS = new byte[0][];
private static final StreamDelegate[] ZERO_VALUES = new StreamDelegate[0];
@ -39,7 +41,7 @@ public class StreamDelegate {
private StreamDelegate add(String name, StreamDelegate scope) {
if (valueReader != null) {
System.out.println("Scope " + name + " | " + scope + " may not run, as the stream is only read once, and a value reader is already set");
getLogger(StreamDelegate.class).warn("Scope {} | {} may not run, as the stream is only read once, and a value reader is already set", name, scope);
}
byte[] bytes = name.getBytes(NBTConstants.CHARSET);
int maxSize = bytes.length;
@ -167,7 +169,7 @@ public class StreamDelegate {
public StreamDelegate withValue(ValueReader valueReader) {
if (keys.length != 0) {
System.out.println("Reader " + valueReader + " may not run, as the stream is only read once, and a value reader is already set");
getLogger(StreamDelegate.class).warn("Reader {} may not run, as the stream is only read once, and a value reader is already set", valueReader);
}
this.valueReader = valueReader;
return this;

View File

@ -12,6 +12,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.UUID;
import static org.slf4j.LoggerFactory.getLogger;
public class RollbackOptimizedHistory extends DiskStorageHistory {
private long time;
@ -32,7 +34,7 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
super(world, uuid);
this.time = System.currentTimeMillis();
}
public RollbackOptimizedHistory(World world, UUID uuid, int index, long time, long size, CuboidRegion region, String command) {
super(world, uuid, index);
this.time = time;
@ -45,7 +47,7 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
this.blockSize = (int) size;
this.command = command;
this.closed = true;
System.out.println("Size " + size);
getLogger(RollbackOptimizedHistory.class).debug("Size {}", size);
}
public long getTime() {

View File

@ -30,6 +30,8 @@ import java.util.Iterator;
import java.util.UUID;
import java.util.function.Supplier;
import static org.slf4j.LoggerFactory.getLogger;
public class InspectBrush extends BrushTool {
/**
@ -62,13 +64,13 @@ public class InspectBrush extends BrushTool {
public boolean perform(final Player player, LocalSession session, boolean rightClick) {
if (!player.hasPermission("worldedit.tool.inspect")) {
player.print(Caption.of("", "worldedit.tool.inspect"));
System.out.println("No tool control");
getLogger(InspectBrush.class).debug("No tool control");
return false;
}
if (!Settings.IMP.HISTORY.USE_DATABASE) {
player.print(Caption.of("fawe.error.setting.disable",
"history.use-database (Import with /history import )"));
System.out.println("No db");
getLogger(InspectBrush.class).debug("No db");
return false;
}
try {
@ -109,10 +111,9 @@ public class InspectBrush extends BrushTool {
}
player.print(Caption.of("fawe.worldedit.tool.tool.inspect.info.footer", count));
} catch (IOException e) {
System.out.println("IOE");
throw new RuntimeException(e);
} catch (Throwable e) {
System.out.println("E throw");
getLogger(InspectBrush.class).error("E throw", e);
}
return true;
}

View File

@ -352,7 +352,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
public IChunkSet getChunk(int chunkX, int chunkZ) {
// TODO don't generate new Writeable MCA chunk
System.out.println("TODO don't generate new Writeable MCA chunk");
MCAChunk tmp = new MCAChunk();
int bx = chunkX << 4;
int bz = chunkZ << 4;

View File

@ -38,9 +38,9 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.Locale;
import java.util.UUID;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@ -333,7 +333,7 @@ public class EditSessionBuilder {
// changeSet = new CPUOptimizedChangeSet(world);
} else {
if (combineStages && Settings.IMP.HISTORY.COMPRESSION_LEVEL == 0) {
System.out.println("TODO add CPUOptimizedChangeSet");
//TODO add CPUOptimizedChangeSet
}
changeSet = new MemoryOptimizedHistory(world);
}
@ -346,7 +346,7 @@ public class EditSessionBuilder {
}
if (!(changeSet instanceof NullChangeSet)) {
if (this.blockBag != null) {
System.out.println("TODO implement block bag as IBatchProcessor");
//TODO implement block bag as IBatchProcessor
changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);
}
if (combineStages) {
@ -387,7 +387,7 @@ public class EditSessionBuilder {
this.extent = regionExtent;
}
if (this.limit != null && this.limit.STRIP_NBT != null && !this.limit.STRIP_NBT.isEmpty()) {
System.out.println("TODO add batch processor for strip nbt");
//TODO add batch processor for strip nbt
this.extent = new StripNBTExtent(this.extent, this.limit.STRIP_NBT);
}
this.extent = wrapExtent(this.extent, eventBus, event, EditSession.Stage.BEFORE_HISTORY);

View File

@ -858,7 +858,7 @@ public class MainUtil {
pool.submit(file::delete);
Component msg = TranslatableComponent.of("worldedit.schematic.delete.deleted");
if (printDebug) {
Fawe.debug(msg);
getLogger(MainUtil.class).debug(msg.toString());
}
}
});

View File

@ -652,7 +652,7 @@ public class TextureUtil implements TextureHolder {
String modelFileName = String.format(modelsDir, nameSpace, name);
ZipEntry entry = getEntry(zipFile, modelFileName);
if (entry == null) {
System.out.println("Cannot find " + modelFileName + " in " + file);
getLogger(TextureUtil.class).error("Cannot find {} in {}", modelFileName, file);
continue;
}
@ -690,7 +690,7 @@ public class TextureUtil implements TextureHolder {
BufferedImage image = readImage(zipFile, textureFileName);
if (image == null) {
System.out.println("Cannot find " + textureFileName);
getLogger(TextureUtil.class).error("Cannot find {}", textureFileName);
continue;
}
int color = ImageUtil.getColor(image);

View File

@ -69,6 +69,7 @@ import static com.sk89q.worldedit.util.Direction.UP;
import static com.sk89q.worldedit.util.Direction.WEST;
import static com.sk89q.worldedit.util.Direction.findClosest;
import static com.sk89q.worldedit.util.Direction.values;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Transforms blocks themselves (but not their position) according to a
@ -149,7 +150,7 @@ public class BlockTransformExtent extends ResettableExtent {
case 2:
return adapt(combine(EAST, WEST), combine(SOUTH, NORTH));
default:
System.out.println("Invalid " + property.getName() + " " + property.getValues());
getLogger(BlockTransformExtent.class).error("Invalid {} {}", property.getName(), property.getValues());
return null;
}
case FACING: {
@ -181,7 +182,7 @@ public class BlockTransformExtent extends ResettableExtent {
result.add(notIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("inner_left"), property.getIndexFor("inner_right")));
continue;
default:
System.out.println("Unknown direction " + value);
getLogger(BlockTransformExtent.class).warn("Unknown direction {}", value);
result.add(0L);
}
}
@ -221,7 +222,7 @@ public class BlockTransformExtent extends ResettableExtent {
directions.add(combine(NORTHEAST));
break;
default:
System.out.println("Unknown direction " + value);
getLogger(BlockTransformExtent.class).warn("Unknown direction {}", value);
directions.add(0L);
}
}

View File

@ -160,9 +160,9 @@ public class MaskIntersection extends AbstractMask {
while (combineMasks(pairingFunction(), failedCombines) && --maxIteration > 0);
if (maxIteration == 0) {
getLogger(MaskIntersection.class).debug("Failed optimize MaskIntersection");
getLogger(MaskIntersection.class).error("Failed optimize MaskIntersection");
for (Mask mask : masks) {
System.out.println(mask.getClass() + " / " + mask);
getLogger(MaskIntersection.class).error(mask.getClass() + " / " + mask);
}
}
// Return result

View File

@ -409,7 +409,7 @@ public class EllipsoidRegion extends AbstractRegion {
int yTopFull = Math.min(255, cy + diffYFull);
if (yBotFull == yTopFull || yBotFull > yTopFull) {
System.out.println("aa");
System.out.println("aa"); //why do we print "aa" here?
}
// Set those layers
filter(chunk, filter, block, get, set, yBotFull, yTopFull, full);

View File

@ -25,6 +25,8 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.slf4j.LoggerFactory.getLogger;
public class BlockTypesCache {
/*
-----------------------------------------------------
@ -203,7 +205,7 @@ public class BlockTypesCache {
String defaultState = blockMap.remove(id);
if (defaultState == null) {
if (internalId != 0) {
System.out.println("Ignoring invalid block " + id);
getLogger(BlockTypesCache.class).info("Ignoring invalid block {}", id);
continue;
}
defaultState = id;