Move logging options to seperate static variables

This commit is contained in:
ME1312 2019-01-17 13:12:32 -05:00
parent fcde0bc845
commit 36c33b3bc0
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
2 changed files with 17 additions and 6 deletions

View File

@ -16,6 +16,7 @@ import net.ME1312.Galaxi.Library.Version.VersionType;
import net.ME1312.Galaxi.Plugin.Plugin;
import net.ME1312.Galaxi.Plugin.PluginInfo;
import net.ME1312.SubServers.Host.Executable.SubCreator;
import net.ME1312.SubServers.Host.Executable.SubLogger;
import net.ME1312.SubServers.Host.Executable.SubServer;
import net.ME1312.SubServers.Host.Library.*;
import net.ME1312.SubServers.Host.Network.Cipher;
@ -190,6 +191,9 @@ public final class ExHost {
}
}
Util.reflect(SubLogger.class.getDeclaredField("logn"), null, config.get().getSection("Settings").getBoolean("Network-Log", true));
Util.reflect(SubLogger.class.getDeclaredField("logc"), null, config.get().getSection("Settings").getBoolean("Console-Log", true));
engine.getPluginManager().loadPlugins(new UniversalFile(engine.getRuntimeDirectory(), "Plugins"));
running = true;
@ -253,6 +257,13 @@ public final class ExHost {
config.reload();
try {
Util.reflect(SubLogger.class.getDeclaredField("logn"), null, config.get().getSection("Settings").getBoolean("Network-Log", true));
Util.reflect(SubLogger.class.getDeclaredField("logc"), null, config.get().getSection("Settings").getBoolean("Console-Log", true));
} catch (Exception e) {
e.printStackTrace();
}
Cipher cipher = null;
if (!config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE").equalsIgnoreCase("NONE")) {
if (config.get().getSection("Settings").getSection("SubData").getString("Password", "").length() == 0) {

View File

@ -23,6 +23,8 @@ public class SubLogger {
protected final String name;
protected UUID address;
protected Container<Boolean> log;
protected static boolean logn = true;
protected static boolean logc = true;
protected File file;
private PrintWriter writer = null;
private boolean started = false;
@ -71,12 +73,10 @@ public class SubLogger {
@SuppressWarnings("deprecation")
private void start(InputStream in, boolean isErr) {
try {
boolean network = SubAPI.getInstance().getInternals().config.get().getSection("Settings").getBoolean("Network-Log", true),
console = SubAPI.getInstance().getInternals().config.get().getSection("Settings").getBoolean("Console-Log", true);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = br.readLine()) != null) {
log(line, network, console);
log(line);
}
} catch (IOException e) {} finally {
if (isErr) {
@ -89,7 +89,7 @@ public class SubLogger {
}
}
private void log(String line, boolean network, boolean console) {
private void log(String line) {
if (!line.startsWith(">")) {
String msg = line;
LogStream level;
@ -121,10 +121,10 @@ public class SubLogger {
}
// Log to NETWORK
if (log.get() && network) SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketOutExLogMessage(address, line));
if (log.get() && logn) SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketOutExLogMessage(address, line));
// Log to CONSOLE
if (log.get() && console) level.println(TextColor.convertColor(msg));
if (log.get() && logc) level.println(TextColor.convertColor(msg));
// Log to FILE
if (writer != null) {