mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-06-23 13:14:51 +02:00
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.
55 lines
1.7 KiB
Java
55 lines
1.7 KiB
Java
package net.ME1312.SubServers.Host.Library.Log;
|
|
|
|
import net.ME1312.SubServers.Host.Library.NamedContainer;
|
|
import net.ME1312.SubServers.Host.SubAPI;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.lang.reflect.Field;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* System.out and System.err Override Class
|
|
*/
|
|
public final class SystemLogger extends OutputStream {
|
|
private NamedContainer<String, Logger> last = new NamedContainer<String, Logger>("", null);
|
|
private boolean error;
|
|
|
|
protected SystemLogger(boolean level) throws IOException {
|
|
this.error = level;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
private List<String> getKnownClasses() {
|
|
List<String> value = null;
|
|
try {
|
|
Field f = SubAPI.class.getDeclaredField("knownClasses");
|
|
f.setAccessible(true);
|
|
value = (List<String>) f.get(SubAPI.getInstance());
|
|
f.setAccessible(false);
|
|
} catch (Exception e) {}
|
|
return value;
|
|
}
|
|
|
|
@Override
|
|
public void write(int c) throws IOException {
|
|
int i = 0;
|
|
String origin = java.lang.System.class.getCanonicalName();
|
|
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
|
|
if (i > 1 && getKnownClasses().contains(element.getClassName())) {
|
|
origin = element.getClassName().replaceFirst("\\$.*", "");
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
if (!last.name().equals(origin)) last = new NamedContainer<String, Logger>(origin, new Logger(origin));
|
|
if (error) {
|
|
last.get().error.print((char) c);
|
|
} else {
|
|
last.get().info.print((char) c);
|
|
}
|
|
}
|
|
}
|
|
|