mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Revise logging GC strategy
This commit is contained in:
parent
9cb499c4ec
commit
eb70ebaeea
@ -19,8 +19,8 @@ public class Executable {
|
||||
String[] cmd;
|
||||
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
||||
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
||||
exec = "\"" + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + "\"";
|
||||
exec = '"' + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + '"';
|
||||
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||
} else {
|
||||
cmd = new String[]{"sh", "-lc", exec};
|
||||
|
@ -71,22 +71,8 @@ public class ExternalSubLogger extends SubLogger {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the External Logger Address
|
||||
*
|
||||
* @return External Address
|
||||
*/
|
||||
public UUID getExternalAddress() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a Message
|
||||
*
|
||||
* @param line Message
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void log(String line) {
|
||||
private void log(String line) {
|
||||
if (started) {
|
||||
String msg = line;
|
||||
Level level;
|
||||
@ -134,12 +120,18 @@ public class ExternalSubLogger extends SubLogger {
|
||||
writer.println(line);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
gc++;
|
||||
gc();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the External Logger Address
|
||||
*
|
||||
* @return External Address
|
||||
*/
|
||||
public UUID getExternalAddress() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFilter(SubLogFilter filter) {
|
||||
if (Util.isNull(filter)) throw new NullPointerException();
|
||||
|
@ -78,6 +78,20 @@ public class InternalSubLogger extends SubLogger {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
log(line);
|
||||
}
|
||||
} catch (IOException e) {} finally {
|
||||
if (isErr) {
|
||||
err = null;
|
||||
} else {
|
||||
out = null;
|
||||
}
|
||||
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String line) {
|
||||
if (!line.startsWith(">")) {
|
||||
String msg = line;
|
||||
Level level;
|
||||
@ -125,19 +139,6 @@ public class InternalSubLogger extends SubLogger {
|
||||
writer.println(line);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
gc++;
|
||||
gc();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {} finally {
|
||||
if (isErr) {
|
||||
err = null;
|
||||
} else {
|
||||
out = null;
|
||||
}
|
||||
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,17 +4,6 @@ package net.ME1312.SubServers.Bungee.Host;
|
||||
* SubLogger Layout Class
|
||||
*/
|
||||
public abstract class SubLogger {
|
||||
public static final int MAX_GC = Integer.getInteger("subservers.logging.max_gc", 4096);
|
||||
private static boolean gc_running = false;
|
||||
protected static int gc = 0;
|
||||
protected static void gc() {
|
||||
if (!gc_running && MAX_GC > 0 && gc >= MAX_GC) {
|
||||
gc_running = true;
|
||||
System.gc();
|
||||
gc = 0;
|
||||
gc_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Name of the task logging
|
||||
|
@ -7,6 +7,7 @@ import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -25,7 +26,10 @@ public class PacketInExLogMessage implements PacketIn {
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
try {
|
||||
if (data.contains("h") && data.contains("m") && data.getRawString("m").length() != 0 && loggers.keySet().contains(UUID.fromString(data.getRawString("h")))) {
|
||||
loggers.get(UUID.fromString(data.getRawString("h"))).log(data.getRawString("m"));
|
||||
Method m = ExternalSubLogger.class.getDeclaredMethod("log", String.class);
|
||||
m.setAccessible(true);
|
||||
m.invoke(loggers.get(UUID.fromString(data.getRawString("h"))), data.getRawString("m"));
|
||||
m.setAccessible(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -19,8 +19,8 @@ public class Executable {
|
||||
String[] cmd;
|
||||
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
||||
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
||||
exec = "\"" + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + "\"";
|
||||
exec = '"' + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + '"';
|
||||
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||
} else {
|
||||
cmd = new String[]{"sh", "-lc", exec};
|
||||
|
@ -17,7 +17,6 @@ import java.util.regex.Pattern;
|
||||
* Internal Process Logger Class
|
||||
*/
|
||||
public class SubLogger {
|
||||
public static final int MAX_GC = Integer.getInteger("subservers.logging.max_gc", 4096);
|
||||
protected Process process;
|
||||
private Object handle;
|
||||
protected final Logger logger;
|
||||
@ -50,17 +49,6 @@ public class SubLogger {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
private static boolean gc_running = false;
|
||||
private static int gc = 0;
|
||||
private static void gc() {
|
||||
if (!gc_running && MAX_GC > 0 && gc >= MAX_GC) {
|
||||
gc_running = true;
|
||||
System.gc();
|
||||
gc = 0;
|
||||
gc_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Logger
|
||||
*/
|
||||
@ -83,10 +71,25 @@ public class SubLogger {
|
||||
@SuppressWarnings("deprecation")
|
||||
private void start(InputStream in, boolean isErr) {
|
||||
try {
|
||||
YAMLSection yaml = SubAPI.getInstance().getInternals().config.get().getSection("Settings");
|
||||
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);
|
||||
}
|
||||
} catch (IOException e) {} finally {
|
||||
if (isErr) {
|
||||
err = null;
|
||||
} else {
|
||||
out = null;
|
||||
}
|
||||
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String line, boolean network, boolean console) {
|
||||
if (!line.startsWith(">")) {
|
||||
String msg = line;
|
||||
LogStream level;
|
||||
@ -118,29 +121,16 @@ public class SubLogger {
|
||||
}
|
||||
|
||||
// Log to NETWORK
|
||||
if (log.get() && yaml.getBoolean("Network-Log", true)) SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketOutExLogMessage(address, line));
|
||||
if (log.get() && network) SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketOutExLogMessage(address, line));
|
||||
|
||||
// Log to CONSOLE
|
||||
if (log.get() && yaml.getBoolean("Console-Log", true)) level.println(TextColor.convertColor(msg));
|
||||
if (log.get() && console) level.println(TextColor.convertColor(msg));
|
||||
|
||||
// Log to FILE
|
||||
if (writer != null) {
|
||||
writer.println(line);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
gc++;
|
||||
gc();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {} finally {
|
||||
if (isErr) {
|
||||
err = null;
|
||||
} else {
|
||||
out = null;
|
||||
}
|
||||
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user