Add STATUS stream and use instead of INIT in some places.

* STATUS logs to console and default file, using queues.
* StaticLog logs to STATUS during runtime.
This commit is contained in:
asofold 2014-11-23 15:47:10 +01:00
parent 3460e29246
commit 0561638105
4 changed files with 35 additions and 8 deletions

View File

@ -80,6 +80,7 @@ public class LogManager extends AbstractLogManager {
*/
protected void createDefaultLoggers(ConfigFile config) {
for (StreamID streamID : new StreamID[] {
Streams.STATUS,
Streams.SERVER_LOGGER, Streams.PLUGIN_LOGGER,
Streams.NOTIFY_INGAME,
Streams.DEFAULT_FILE, Streams.TRACE_FILE,
@ -94,6 +95,7 @@ public class LogManager extends AbstractLogManager {
// Server logger.
tempID = registerStringLogger(Bukkit.getLogger(), new LogOptions(Streams.SERVER_LOGGER.name, bukkitLoggerContext));
attachStringLogger(tempID, Streams.SERVER_LOGGER);
attachStringLogger(tempID, Streams.STATUS); // Log STATUS to console "efficiently".
// Plugin logger.
tempID = registerStringLogger(plugin.getLogger(), new LogOptions(Streams.PLUGIN_LOGGER.name, bukkitLoggerContext));
@ -122,6 +124,7 @@ public class LogManager extends AbstractLogManager {
ContentLogger<String> defaultFileLogger = new FileLoggerAdapter(file); // TODO: Method to get-or-create these.
tempID = registerStringLogger(defaultFileLogger, new LogOptions(Streams.DEFAULT_FILE.name, CallContext.ASYNCHRONOUS_DIRECT));
attachStringLogger(tempID, Streams.DEFAULT_FILE);
attachStringLogger(tempID, Streams.STATUS); // Log STATUS to the default file.
// Attach default file logger to init too, to log something, even if asynchronous, directly from any thread.
tempID = registerStringLogger(defaultFileLogger, new LogOptions(Streams.DEFAULT_FILE.name +".init", CallContext.ANY_THREAD_DIRECT));
attachStringLogger(tempID, Streams.INIT);

View File

@ -7,7 +7,9 @@ import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
/**
* Static access methods for more or less direct logging using either LogManager/INIT or System.out.
* Static access methods for more or less direct logging using either LogManager
* (usually INIT or STATUS) or System.out.
*
* @author mc_dev
*
*/
@ -15,7 +17,9 @@ public class StaticLog {
// TODO: Remove this class, instead use an implementation of LogManager for testing.
private static boolean useLogManager = false; // Let the plugin control this.
private static boolean useLogManager = false;
private static StreamID streamID = Streams.INIT;
/**
* Now needs to be set, in order to log to the INIT stream instead of the console.
@ -24,6 +28,13 @@ public class StaticLog {
public static void setUseLogManager(boolean useLogManager) {
StaticLog.useLogManager = useLogManager;
}
public static void setStreamID(StreamID streamID) {
if (streamID == null) {
throw new NullPointerException("StreamID must not be null, use setUseLogManager(false) instead.");
}
StaticLog.streamID = streamID;
}
public static void logInfo(final String msg) {
log(Level.INFO, msg);
@ -51,7 +62,7 @@ public class StaticLog {
public static void log(final Level level, final String msg) {
if (useLogManager) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().log(Streams.INIT, level, msg);
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().log(streamID, level, msg);
} else {
System.out.println("[" + level + "] " + new Date());
System.out.println(msg);

View File

@ -23,7 +23,7 @@ public class Streams {
*/
public static final String defaultPrefix = "default.";
// More or less raw default streams.
// Abstract default streams ---
/**
* Default stream for initialization and shutdown, should always be
@ -34,6 +34,17 @@ public class Streams {
*/
public static final StreamID INIT = new StreamID(defaultPrefix + "init");
/**
* Stream for status and error messages similar to INIT, but using queues
* and scheduling. Potentially more efficient, for less severe cases.
* Usually logging both to console and log file.
*/
public static final StreamID STATUS = new StreamID(defaultPrefix + "status");
// TODO: Consider TRACE.
// Raw default streams ---
/**
* Default stream for the server logger (think of console). Might not allow
* asynchronous access, thus using a task in the primary thread by default.
@ -64,6 +75,4 @@ public class Streams {
*/
public static final StreamID TRACE_FILE = new StreamID(defaultPrefix + "file.trace");
// TODO: Abstract streams: INIT, STATUS, ACTIONS, TRACE. STATUS being similar to INIT, just allowing to use tasks.
}

View File

@ -654,9 +654,10 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
logManager.info(Streams.INIT, "[NoCheatPlus] Shutdown LogManager...");
}
StaticLog.setUseLogManager(false);
StaticLog.setStreamID(Streams.INIT);
logManager.shutdown();
// Tell the server administrator the we finished unloading NoCheatPlus.
// Tell the server administrator that we finished unloading NoCheatPlus.
if (verbose) {
Bukkit.getLogger().info("[NoCheatPlus] All cleanup done.");
}
@ -716,6 +717,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.setStreamID(Streams.INIT);
StaticLog.setUseLogManager(true);
logManager.info(Streams.INIT, "[NoCheatPlus] Logging system initialized.");
}
@ -893,7 +895,9 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
);
}
});
// Set StaticLog to more efficient output.
StaticLog.setStreamID(Streams.STATUS);
// Tell the server administrator that we finished loading NoCheatPlus now.
logManager.info(Streams.INIT, "[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled.");
}