From c0b2237a12fc878ede8a8bbd48c9b4afa8290016 Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 23 Apr 2020 23:27:33 +0800 Subject: Split Log4j --- .../com/keuin/kbackupfabric/worker/BackupWorker.java | 11 +++++++---- .../keuin/kbackupfabric/worker/RestoreWorker.java | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/keuin/kbackupfabric/worker') diff --git a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java index 0ca9015..57e59fb 100644 --- a/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java +++ b/src/main/java/com/keuin/kbackupfabric/worker/BackupWorker.java @@ -8,6 +8,8 @@ import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.world.World; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.io.IOException; @@ -15,7 +17,6 @@ import java.util.HashMap; import java.util.Map; import static com.keuin.kbackupfabric.util.BackupFilesystemUtil.*; -import static com.keuin.kbackupfabric.util.PrintUtil.debug; import static com.keuin.kbackupfabric.util.PrintUtil.msgInfo; /** @@ -23,6 +24,8 @@ import static com.keuin.kbackupfabric.util.PrintUtil.msgInfo; * To invoke this worker, simply call invoke() method. */ public final class BackupWorker implements Runnable { + + private static final Logger LOGGER = LogManager.getLogger(); private final CommandContext context; private final String backupName; private final Map oldWorldsSavingDisabled; @@ -53,9 +56,9 @@ public final class BackupWorker implements Runnable { }); // Force to save all player data and worlds - debug("Saving players ..."); + LOGGER.debug("Saving players ..."); server.getPlayerManager().saveAllPlayerData(); - debug("Saving worlds ..."); + LOGGER.debug("Saving worlds ..."); server.save(true, true, true); // Start threaded worker @@ -82,7 +85,7 @@ public final class BackupWorker implements Runnable { // Make zip String levelPath = getLevelPath(server); String backupFileName = getBackupFileName(backupName); - debug(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectoryFile.toString())); + LOGGER.debug(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectoryFile.toString())); ZipUtil.makeBackupZip(levelPath, backupSaveDirectoryFile.toString(), backupFileName, backupMetadata); File backupZipFile = new File(backupSaveDirectoryFile, backupFileName); diff --git a/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java b/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java index 9e424d7..8d367d7 100644 --- a/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java +++ b/src/main/java/com/keuin/kbackupfabric/worker/RestoreWorker.java @@ -3,11 +3,12 @@ package com.keuin.kbackupfabric.worker; import com.keuin.kbackupfabric.util.ZipUtil; import com.keuin.kbackupfabric.util.ZipUtilException; import net.minecraft.server.MinecraftServer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.io.IOException; -import static com.keuin.kbackupfabric.util.PrintUtil.*; import static org.apache.commons.io.FileUtils.forceDelete; /** @@ -15,6 +16,9 @@ import static org.apache.commons.io.FileUtils.forceDelete; * To invoke this worker, simply call invoke() method. */ public final class RestoreWorker implements Runnable { + + private static final Logger LOGGER = LogManager.getLogger(); + private final Thread serverThread; private final String backupFilePath; private final String levelDirectory; @@ -40,7 +44,7 @@ public final class RestoreWorker implements Runnable { public void run() { try { // Wait server thread die - debug("Waiting server thread stopping ..."); + LOGGER.debug("Waiting for the server thread to exit ..."); while (serverThread.isAlive()) { try { serverThread.join(); @@ -48,14 +52,14 @@ public final class RestoreWorker implements Runnable { } } - debug("Wait for 5 seconds ..."); + LOGGER.debug("Wait for 5 seconds ..."); try { Thread.sleep(5000); } catch (InterruptedException ignored) { } // Delete old level - debug("Server stopped. Deleting old level ..."); + LOGGER.debug("Server stopped. Deleting old level ..."); File levelDirFile = new File(levelDirectory); int failedCounter = 0; @@ -75,16 +79,16 @@ public final class RestoreWorker implements Runnable { } } if (levelDirFile.exists()) { - error(String.format("Cannot restore: failed to delete old level %s .", levelDirFile.getName())); + LOGGER.error(String.format("Cannot restore: failed to delete old level %s .", levelDirFile.getName())); return; } // Decompress archive - debug("Decompressing archived level"); + LOGGER.debug("Decompressing archived level"); ZipUtil.unzip(backupFilePath, levelDirectory, false); - info("Restore complete! Please restart the server manually."); + LOGGER.info("Restore complete! Please restart the server manually."); } catch (SecurityException | IOException | ZipUtilException e) { - error("An exception occurred while restoring: " + e.getMessage()); + LOGGER.error("An exception occurred while restoring: " + e.getMessage()); } } } -- cgit v1.2.3