Remove StaticLog.schedule... and toString(Throwable).

This commit is contained in:
asofold 2014-11-21 23:45:02 +01:00
parent 4ffca941a2
commit 3460e29246
5 changed files with 19 additions and 113 deletions

View File

@ -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();
}

View File

@ -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<E extends Event> 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) {

View File

@ -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 <O extends Object> boolean scheduleLogInfo(final List<O> 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 <O extends Object> boolean scheduleLog(final Level level, final List<O> parts, final String link)
{
return scheduleLog(level, StringUtil.join(parts, link));
}
}

View File

@ -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.");
}

View File

@ -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