diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java index eeb5133c..62d9b389 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java @@ -18,7 +18,7 @@ import fr.neatmonster.nocheatplus.components.INotifyReload; import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI; import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigManager; -import fr.neatmonster.nocheatplus.logging.StaticLog; +import fr.neatmonster.nocheatplus.logging.Streams; import fr.neatmonster.nocheatplus.utilities.ColorUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil; @@ -307,7 +307,7 @@ public class Text extends Check implements INotifyReload { debugParts.add("Normal: min=" + StringUtil.fdec3.format(cc.textFreqNormMin) +", weight=" + StringUtil.fdec3.format(cc.textFreqNormWeight) + " => accumulated=" + StringUtil.fdec3.format(accumulated)); debugParts.add("Short-term: min=" + StringUtil.fdec3.format(cc.textFreqShortTermMin) +", weight=" + StringUtil.fdec3.format(cc.textFreqShortTermWeight) + " => accumulated=" + StringUtil.fdec3.format(shortTermAccumulated)); debugParts.add("vl: " + StringUtil.fdec3.format(data.textVL)); - StaticLog.scheduleLogInfo(debugParts, " | "); + NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, StringUtil.join(debugParts, " | ")); debugParts.clear(); } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/event/GenericListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/event/GenericListener.java index 4ce008fc..31dccdfd 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/event/GenericListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/event/GenericListener.java @@ -14,7 +14,8 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.EventExecutor; import org.bukkit.plugin.Plugin; -import fr.neatmonster.nocheatplus.logging.StaticLog; +import fr.neatmonster.nocheatplus.NCPAPIProvider; +import fr.neatmonster.nocheatplus.logging.Streams; /** * listener registered for one event only. Allows to delegate to other registered listeners. @@ -113,15 +114,7 @@ public class GenericListener implements Listener, EventExecutor private void onError(final MethodEntry entry, final Event event, final Throwable t) { final String descr = "GenericListener<" + clazz.getName() +"> @" + priority +" encountered an exception for " + entry.listener.getClass().getName() + " with method " + entry.method.toGenericString(); - try{ - final EventException e = new EventException(t, descr); - // TODO: log it / more details! - if (event.isAsynchronous()) StaticLog.scheduleLogSevere(e); - else StaticLog.logSevere(e); - } - catch (Throwable t2){ - StaticLog.scheduleLogSevere("Could not log exception: " + descr); - } + NCPAPIProvider.getNoCheatPlusAPI().getLogManager().severe(Streams.SERVER_LOGGER, new EventException(t, descr)); } public void register(Plugin plugin) { diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/StaticLog.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/StaticLog.java index bb583c43..edae86d3 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/StaticLog.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/StaticLog.java @@ -1,7 +1,6 @@ package fr.neatmonster.nocheatplus.logging; import java.util.Date; -import java.util.List; import java.util.logging.Level; import fr.neatmonster.nocheatplus.NCPAPIProvider; @@ -14,24 +13,18 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil; */ public class StaticLog { - // TODO: Remove this class (needs a version of LogManager for testing, i.e. ). + // TODO: Remove this class, instead use an implementation of LogManager for testing. - private static boolean useBukkitLogger = false; // Let the plugin control this. + private static boolean useLogManager = false; // Let the plugin control this. /** - * This is for testing purposes only. - * @param use + * Now needs to be set, in order to log to the INIT stream instead of the console. + * @param useLogManager */ - public static void setUseBukkitLogger(boolean use) { - useBukkitLogger = use; + public static void setUseLogManager(boolean useLogManager) { + StaticLog.useLogManager = useLogManager; } - // TODO: Remove toString method ! - public static String toString(final Throwable t){ - return StringUtil.throwableToString(t); - } - - public static void logInfo(final String msg) { log(Level.INFO, msg); } @@ -45,19 +38,19 @@ public class StaticLog { } public static void logInfo(final Throwable t) { - log(Level.INFO, toString(t)); + log(Level.INFO, StringUtil.throwableToString(t)); } public static void logWarning(final Throwable t) { - log(Level.WARNING, toString(t)); + log(Level.WARNING, StringUtil.throwableToString(t)); } public static void logSevere(final Throwable t) { - log(Level.SEVERE, toString(t)); + log(Level.SEVERE, StringUtil.throwableToString(t)); } public static void log(final Level level, final String msg) { - if (useBukkitLogger) { + if (useLogManager) { NCPAPIProvider.getNoCheatPlusAPI().getLogManager().log(Streams.INIT, level, msg); } else { System.out.println("[" + level + "] " + new Date()); @@ -65,84 +58,4 @@ public class StaticLog { } } - /** - * Schedule a message to be output by the bukkit logger at info level, scheduled as task for NoCheatPlus. - * - * @param message - * @return If scheduled successfully. - */ - public static boolean scheduleLogInfo(final String message) { - return scheduleLog(Level.INFO, message); - } - - /** - * Schedule a message to be output by the bukkit logger at warning level, scheduled as task for NoCheatPlus. - * - * @param message - * @return If scheduled successfully. - */ - public static boolean scheduleLogWarning(final String message) { - return scheduleLog(Level.WARNING, message); - } - - /** - * Schedule a message to be output by the bukkit logger at warning level, scheduled as task for NoCheatPlus. - * - * @param message - * @return If scheduled successfully. - */ - public static boolean scheduleLogSevere(final String message) { - return scheduleLog(Level.SEVERE, message); - } - - public static boolean scheduleLogInfo(final Throwable t) { - return scheduleLog(Level.INFO, toString(t)); - } - - public static boolean scheduleLogWarning(final Throwable t) { - return scheduleLog(Level.WARNING, toString(t)); - } - - public static boolean scheduleLogSevere(final Throwable t) { - return scheduleLog(Level.SEVERE, toString(t)); - } - - /** - * Same as log(level, message). - * - * @deprecated Same as log(level, message). - * - * @param level - * @param message - * @return - */ - public static boolean scheduleLog(final Level level, final String message) { - StaticLog.log(level, message); - return true; - } - - /** - * Log joined parts on info level. - * @param level - * @param parts - * @param link - * @return - */ - public static boolean scheduleLogInfo(final List parts, final String link) - { - return scheduleLog(Level.INFO, parts, link); - } - - /** - * Log joined parts on the given level. - * @param level - * @param parts - * @param link - * @return - */ - public static boolean scheduleLog(final Level level, final List parts, final String link) - { - return scheduleLog(level, StringUtil.join(parts, link)); - } - } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java index 6988d26a..eaa32a2a 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java @@ -653,7 +653,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { if (verbose) { logManager.info(Streams.INIT, "[NoCheatPlus] Shutdown LogManager..."); } - StaticLog.setUseBukkitLogger(false); + StaticLog.setUseLogManager(false); logManager.shutdown(); // Tell the server administrator the we finished unloading NoCheatPlus. @@ -716,7 +716,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { // Read the configuration files. ConfigManager.init(this); // TODO: Only load the bootstrap config (not all). logManager = new LogManager(this); - StaticLog.setUseBukkitLogger(true); + StaticLog.setUseLogManager(true); logManager.info(Streams.INIT, "[NoCheatPlus] Logging system initialized."); } diff --git a/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestPassableRayTracing.java b/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestPassableRayTracing.java index 49755c5a..80fa4235 100644 --- a/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestPassableRayTracing.java +++ b/NCPPlugin/src/test/java/fr/neatmonster/nocheatplus/test/TestPassableRayTracing.java @@ -17,9 +17,9 @@ public class TestPassableRayTracing { // TODO: Randomized tests (Collide with inner sphere, not collide with outer sphere). public TestPassableRayTracing() { - StaticLog.setUseBukkitLogger(false); + StaticLog.setUseLogManager(false); BlockTests.initBlockProperties(); - StaticLog.setUseBukkitLogger(true); + StaticLog.setUseLogManager(true); } @Test