SubServers-2/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Log/Logger.java
ME1312 eb18c01b22 Rewrite Launch & PluginLoader for SubServers.Host
This commit changes the way SubServers.Host launches itself and loads it's plugins. Overall loading plugins this way is more efficient, faster, and can cause less problems than before.

Plugins will still use the package.xml & @SubPlugin annotation system to be loaded.

Also, there are some changes to the logger that better support async logging.
2018-01-21 15:45:27 -05:00

59 lines
2.0 KiB
Java

package net.ME1312.SubServers.Host.Library.Log;
import jline.console.ConsoleReader;
import net.ME1312.SubServers.Host.Library.Container;
import net.ME1312.SubServers.Host.Library.Util;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URLDecoder;
/**
* Logger Class
*/
public final class Logger {
private static final Container<PrintStream> pso = new Container<PrintStream>(null);
private static final Container<PrintStream> pse = new Container<PrintStream>(null);
/**
* Setup the SubServers Log System
*
* @param out System.out
* @param err System.err
* @param in jline.in
* @param dir Runtime Directory
* @throws IOException
*/
public static void setup(PrintStream out, PrintStream err, ConsoleReader in, File dir) throws IOException {
if (Util.isNull(out, err, dir)) throw new NullPointerException();
if (pso.get() == null || pse.get() == null) {
pso.set(new PrintStream(new FileLogger(new ConsoleStream(in, out), dir)));
pse.set(new PrintStream(new FileLogger(new ConsoleStream(in, err), dir)));
System.setOut(new PrintStream(new SystemLogger(false)));
System.setErr(new PrintStream(new SystemLogger(true)));
}
}
/**
* Gets a new Logger
*
* @param prefix Log Prefix
*/
public Logger(String prefix) {
if (Util.isNull(prefix)) throw new NullPointerException();
if (prefix.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty prefix");
message = new LogStream(prefix, "MESSAGE", pso);
info = new LogStream(prefix, "INFO", pso);
warn = new ErrorStream(prefix, "WARN", pso);
error = new ErrorStream(prefix, "ERROR", pse);
severe = new ErrorStream(prefix, "SEVERE", pse);
}
public final LogStream message;
public final LogStream info;
public final ErrorStream warn;
public final ErrorStream error;
public final ErrorStream severe;
}