Skip to content

Commit

Permalink
replace printStackTrace with log
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Apr 2, 2024
1 parent 869493d commit 94cac64
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/net/pl3x/map/core/Pl3xMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Pl3xMap(boolean isBukkit) {
}
} catch (Exception e) {
manifest = new Manifest();
e.printStackTrace();
Logger.severe("Failed to obtain Manifest from META-INF", e);
}
this.manifestAttributes = manifest.getMainAttributes();

Expand Down Expand Up @@ -265,7 +265,7 @@ public void enable() {
try {
this.metrics = new Metrics(this);
} catch (IOException e) {
e.printStackTrace();
Logger.severe("Failed to generate or load default bStats config", e);
}

Pl3xMap.api().getRegionProcessor().setPaused(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Queue;
import net.pl3x.map.core.command.exception.PointParseException;
import net.pl3x.map.core.log.Logger;
import net.pl3x.map.core.markers.Point;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -77,7 +78,7 @@ public class PointParser<C> implements ArgumentParser<@NotNull C, @NotNull Point
try {
coordinate = input.isEmpty() ? 0 : Integer.parseInt(input);
} catch (Exception e) {
e.printStackTrace();
Logger.severe("Failed to get integer from coordinate input", e);
return ArgumentParseResult.failure(new IntegerArgument.IntegerParseException(
input,
new IntegerArgument.IntegerParser<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.pl3x.map.core.configuration.Config;
import net.pl3x.map.core.configuration.Lang;
import net.pl3x.map.core.image.io.IO;
import net.pl3x.map.core.log.Logger;
import net.pl3x.map.core.markers.Point;
import net.pl3x.map.core.renderer.Renderer;
import net.pl3x.map.core.world.World;
Expand Down Expand Up @@ -168,7 +169,7 @@ private static String stitchImage(int sizeX, int sizeZ, Map<Point, Path> pngFile
Point point = entry.getKey();
g2d.drawImage(tile, (point.x() - minX) << 9, (point.z() - minZ) << 9, null);
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Could not generate tile from point %s in path %s".formatted(entry.getKey(), entry.getValue().toAbsolutePath()), t);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ protected void reload(@NotNull Path path, @NotNull Class<? extends @NotNull Abst
setComment(key.value(), comment.value());
}
} catch (Throwable e) {
Logger.warn("Failed to load " + key.value() + " from " + path.getFileName().toString());
e.printStackTrace();
Logger.warn("Failed to load " + key.value() + " from " + path.getFileName().toString(), e);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void callEvent(@NotNull Event event) {
Logger.debug("Executing Event " + handler);
handler.execute(event);
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to execute Event " + handler, t);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void startServer() {
long time = attr.lastModifiedTime().toMillis();
return new ETag(false, Long.toString(time));
} catch (IOException e) {
e.printStackTrace();
Logger.severe("Failed to read basic file attributes from file %s".formatted(path.toAbsolutePath()), e);
return null;
}
})
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/net/pl3x/map/core/image/TileImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.pl3x.map.core.Keyed;
import net.pl3x.map.core.configuration.Config;
import net.pl3x.map.core.image.io.IO;
import net.pl3x.map.core.log.Logger;
import net.pl3x.map.core.markers.Point;
import net.pl3x.map.core.util.Colors;
import net.pl3x.map.core.util.FileUtil;
Expand Down Expand Up @@ -107,7 +108,7 @@ public void saveToDisk() {
// finally, save buffer to disk
this.io.write(filePath, buffer);
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to read/write tile at path %s".formatted(filePath), t);
}

lock.writeLock().unlock();
Expand Down
9 changes: 3 additions & 6 deletions core/src/main/java/net/pl3x/map/core/image/io/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public int color(int argb) {
buffer = reader.read(0);
in.flush();
} catch (IOException e) {
Logger.warn("Could not read tile image: " + path);
e.printStackTrace();
Logger.warn("Could not read tile image: " + path, e);
} finally {
if (reader != null) {
reader.dispose();
Expand All @@ -126,8 +125,7 @@ public void write(@NotNull Path path, @NotNull BufferedImage buffer) {
writer.write(null, new IIOImage(buffer, null, null), param);
out.flush();
} catch (IOException e) {
Logger.warn("Could not write tile image: " + tmp);
e.printStackTrace();
Logger.warn("Could not write tile image: " + tmp, e);
} finally {
if (writer != null) {
writer.dispose();
Expand All @@ -136,8 +134,7 @@ public void write(@NotNull Path path, @NotNull BufferedImage buffer) {
try {
FileUtil.atomicMove(tmp, path);
} catch (IOException e) {
Logger.warn("Could not write tile image: " + path);
e.printStackTrace();
Logger.warn("Could not write tile image: " + path, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void run() {
try {
runProgress();
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to run progress", t);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,15 @@ public void run() {
Logger.debug("Found modified region: " + file.getFileName());
modifiedRegions.add(Point.of(rX, rZ));
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed while trying to parse region file %s".formatted(file.toAbsolutePath()), t);
}
}
Pl3xMap.api().getRegionProcessor().addRegions(world, modifiedRegions);
});
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to loop through region files for worlds", t);
}

//

this.running = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void run() {

} catch (ClosedWatchServiceException | InterruptedException ignore) {
} catch (IOException e) {
e.printStackTrace();
Logger.severe("Failed to create a new file watcher for directory %s".formatted(dir.toAbsolutePath()), e);
}

if (this.stopped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void run() {

}
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Region processor failed to process tickets", t);
}

this.running = false;
Expand Down Expand Up @@ -216,7 +216,7 @@ private void schedule(@NotNull World world, @NotNull List<@NotNull Point> ordere
.map(pos -> CompletableFuture.runAsync(new RegionScanTask(world, pos), Pl3xMap.api().getRenderExecutor())
.whenComplete((result, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
Logger.severe("Failed to run region scan task for %s".formatted(world.getName(), pos), throwable);
}

// set region modified time
Expand All @@ -230,7 +230,7 @@ private void schedule(@NotNull World world, @NotNull List<@NotNull Point> ordere
).toArray(CompletableFuture[]::new)
).whenComplete((result, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
Logger.severe("Failed to run region scan tasks for world %s".formatted(world.getName()), throwable);
}

// stop the progress tracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void run() {

saveImages();
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to scan world %s at region %s".formatted(world.getName(), regionPos), t);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import net.pl3x.map.core.Pl3xMap;
import net.pl3x.map.core.log.Logger;
import net.pl3x.map.core.markers.JsonObjectWrapper;
import net.pl3x.map.core.markers.layer.Layer;
import net.pl3x.map.core.markers.marker.Marker;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void run() {
try {
parseLayers();
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to parse Layers", t);
}
this.running = false;
}, this.executor);
Expand Down Expand Up @@ -108,7 +109,7 @@ private void parseLayers() {
this.lastUpdated.put(key, now);
}
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to process layer " + key + "for world " + world.getName(), t);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.pl3x.map.core.configuration.PlayersLayerConfig;
import net.pl3x.map.core.configuration.WorldConfig;
import net.pl3x.map.core.image.io.IO;
import net.pl3x.map.core.log.Logger;
import net.pl3x.map.core.markers.Point;
import net.pl3x.map.core.scheduler.Task;
import net.pl3x.map.core.util.FileUtil;
Expand All @@ -60,7 +61,7 @@ public void run() {
try {
parseSettings();
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to parse settings.json", t);
}
}

Expand Down Expand Up @@ -187,7 +188,7 @@ private void parseSettings() {
map.put("players", parsePlayers());
map.put("worldSettings", parseWorlds());
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to parse players and worlds settings", t);
}

FileUtil.writeJson(this.gson.toJson(map), FileUtil.getTilesDir().resolve("settings.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.pl3x.map.core.log.Logger;
import org.jetbrains.annotations.NotNull;

public class Scheduler {
Expand Down Expand Up @@ -60,7 +61,7 @@ public void tick() {
iter.remove();
}
} catch (Throwable t) {
t.printStackTrace();
Logger.severe("Failed to tick a task", t);
}
this.ticking = false;
}
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/net/pl3x/map/core/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,11 @@ public static void extractDir(@NotNull String sourceDir, @NotNull Path outDir, b
Logger.debug(" <green>writing</green> " + name);
} catch (IOException e) {
Logger.debug(" <red><bold>failed</bold></red> " + name);
Logger.warn("Failed to extract file (" + name + ") from jar!");
e.printStackTrace();
Logger.severe("Failed to extract file (" + name + ") from jar!", e);
}
}
} catch (IOException e) {
e.printStackTrace();
Logger.severe("Failed to extract " + sourceDir + " directory from jar", e);
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/net/pl3x/map/core/world/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.nio.file.Path;
import java.util.Objects;
import net.pl3x.map.core.Pl3xMap;
import net.pl3x.map.core.log.Logger;
import net.querz.mca.CompressionType;
import net.querz.nbt.io.NBTInputStream;
import net.querz.nbt.io.NamedTag;
Expand Down Expand Up @@ -89,7 +90,7 @@ private int getChunkIndex(int chunkX, int chunkZ) {
chunk = loadChunk(raf, index);
} catch (EOFException | FileNotFoundException ignore) {
} catch (IOException e) {
e.printStackTrace();
Logger.severe("Failed to load chunk at region [%d, %d]".formatted(chunkX, chunkZ), e);
}
if (chunk == null) {
return this.chunks[index] = new EmptyChunk(getWorld(), this);
Expand Down

0 comments on commit 94cac64

Please sign in to comment.