Migrate to SLF4J

This commit is contained in:
matt
2019-04-02 18:21:02 -04:00
parent 47e66913e3
commit 29692f3fbe
62 changed files with 1346 additions and 1305 deletions

View File

@ -58,8 +58,13 @@ import com.sk89q.worldedit.util.command.fluent.CommandGraph;
import com.sk89q.worldedit.util.command.fluent.DispatcherNode;
import com.sk89q.worldedit.util.command.parametric.*;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
@ -69,10 +74,8 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import static com.google.common.base.Preconditions.checkNotNull;
@ -80,14 +83,15 @@ import static com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter.
/**
* Handles the registration and invocation of commands.
* <p>
*
* <p>This class is primarily for internal usage.</p>
*/
public final class CommandManager {
public static final Pattern COMMAND_CLEAN_PATTERN = Pattern.compile("^[/]+");
private static final Logger log = Logger.getLogger(CommandManager.class.getCanonicalName());
private static final Logger commandLog = Logger.getLogger(CommandManager.class.getCanonicalName() + ".CommandLog");
private static final Logger log = LoggerFactory.getLogger(CommandManager.class);
private static final java.util.logging.Logger commandLog =
java.util.logging.Logger.getLogger(CommandManager.class.getCanonicalName() + ".CommandLog");
private static final Pattern numberFormatExceptionPattern = Pattern.compile("^For input string: \"(.*)\"$");
private final WorldEdit worldEdit;
@ -124,6 +128,7 @@ public final class CommandManager {
commandLog.addHandler(dynamicHandler);
dynamicHandler.setFormatter(new LogFormat());
// Set up the commands manager
builder = new ParametricBuilder();
builder.setAuthorizer(new ActorAuthorizer());
builder.setDefaultCompleter(new UserCommandCompleter(platformManager));
@ -297,7 +302,7 @@ public final class CommandManager {
}
public void register(Platform platform) {
log.log(Level.FINE, "Registering commands with " + platform.getClass().getCanonicalName());
log.info("Registering commands with " + platform.getClass().getCanonicalName());
this.platform = null;
try {
@ -318,12 +323,12 @@ public final class CommandManager {
File file = new File(config.getWorkingDirectory(), path);
commandLog.setLevel(Level.ALL);
log.log(Level.INFO, "Logging WorldEdit commands to " + file.getAbsolutePath());
log.info("Logging WorldEdit commands to " + file.getAbsolutePath());
try {
dynamicHandler.setHandler(new FileHandler(file.getAbsolutePath(), true));
} catch (IOException e) {
log.log(Level.WARNING, "Could not use command log file " + path + ": " + e.getMessage());
log.warn("Could not use command log file " + path + ": " + e.getMessage());
}
}
@ -418,7 +423,8 @@ public final class CommandManager {
return handleCommandTask(task, locals, null, null, null, null);
}
private Object handleCommandTask(ThrowableSupplier<Throwable> task, CommandLocals locals, @Nullable Actor actor, @Nullable LocalSession session, @Nullable Set<String> failedPermissions, @Nullable FawePlayer fp) {
private Object handleCommandTask(ThrowableSupplier<Throwable> task, CommandLocals locals, @Nullable
Actor actor, @Nullable LocalSession session, @Nullable Set<String> failedPermissions, @Nullable FawePlayer fp) {
Request.reset();
if (actor == null) actor = locals.get(Actor.class);
if (session == null) session = locals.get(LocalSession.class);
@ -474,8 +480,8 @@ public final class CommandManager {
if (message != null) {
actor.printError(BBC.getPrefix() + e.getMessage());
} else {
actor.printError(BBC.getPrefix() + "An unknown FAWE error has occurred! Please see console.");
log.log(Level.SEVERE, "An unknown FAWE error occurred", e);
actor.printError("An unknown error has occurred! Please see console.");
log.error("An unknown error occurred", e);
}
} catch (Throwable e) {
Exception faweException = FaweException.get(e);
@ -485,7 +491,7 @@ public final class CommandManager {
} else {
actor.printError(BBC.getPrefix() + "There was an error handling a FAWE command: [See console]");
actor.printRaw(e.getClass().getName() + ": " + e.getMessage());
log.log(Level.SEVERE, "An unexpected error occurred while handling a FAWE command", e);
log.error("An unexpected error occurred while handling a FAWE command", e);
}
} finally {
final EditSession editSession = locals.get(EditSession.class);
@ -552,7 +558,7 @@ public final class CommandManager {
return dispatcher;
}
public static Logger getLogger() {
public static java.util.logging.Logger getLogger() {
return commandLog;
}

View File

@ -49,25 +49,25 @@ import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Manages registered {@link Platform}s for WorldEdit. Platforms are
* implementations of WorldEdit.
* <p>
*
* <p>This class is thread-safe.</p>
*/
public class PlatformManager {
private static final Logger logger = Logger.getLogger(PlatformManager.class.getCanonicalName());
private static final Logger logger = LoggerFactory.getLogger(PlatformManager.class);
private final WorldEdit worldEdit;
private final CommandManager commandManager;
@ -99,7 +99,7 @@ public class PlatformManager {
public synchronized void register(Platform platform) {
checkNotNull(platform);
logger.log(Level.FINE, "Got request to register " + platform.getClass() + " with WorldEdit [" + super.toString() + "]");
logger.info("Got request to register " + platform.getClass() + " with WorldEdit [" + super.toString() + "]");
// Just add the platform to the list of platforms: we'll pick favorites
// once all the platforms have been loaded
@ -108,9 +108,9 @@ public class PlatformManager {
// Make sure that versions are in sync
if (firstSeenVersion != null) {
if (!firstSeenVersion.equals(platform.getVersion())) {
logger.log(Level.WARNING, "Multiple ports of WorldEdit are installed but they report different versions ({0} and {1}). " +
logger.warn("Multiple ports of WorldEdit are installed but they report different versions ({0} and {1}). " +
"If these two versions are truly different, then you may run into unexpected crashes and errors.",
new Object[]{firstSeenVersion, platform.getVersion()});
new Object[]{ firstSeenVersion, platform.getVersion() });
}
} else {
firstSeenVersion = platform.getVersion();
@ -119,7 +119,7 @@ public class PlatformManager {
/**
* Unregister a platform from WorldEdit.
* <p>
*
* <p>If the platform has been chosen for any capabilities, then a new
* platform will be found.</p>
*
@ -131,7 +131,7 @@ public class PlatformManager {
boolean removed = platforms.remove(platform);
if (removed) {
logger.log(Level.FINE, "Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit");
logger.info("Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit");
boolean choosePreferred = false;
@ -222,7 +222,7 @@ public class PlatformManager {
/**
* Get a list of loaded platforms.
* <p>
*
* <p>The returned list is a copy of the original and is mutable.</p>
*
* @return a list of platforms
@ -497,7 +497,7 @@ public class PlatformManager {
return;
}
final Tool tool = session.getTool(player);
Tool tool = session.getTool(player);
if (tool != null && tool instanceof DoubleActionTraceTool) {
if (tool.canUse(player)) {
FawePlayer<?> fp = FawePlayer.wrap(player);
@ -532,7 +532,7 @@ public class PlatformManager {
return;
}
final Tool tool = session.getTool(player);
Tool tool = session.getTool(player);
if (tool != null && tool instanceof TraceTool) {
if (tool.canUse(player)) {
FawePlayer<?> fp = FawePlayer.wrap(player);