mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-02-16 19:51:26 +01:00
Revise logging GC strategy
This commit is contained in:
parent
9cb499c4ec
commit
eb70ebaeea
@ -19,8 +19,8 @@ public class Executable {
|
|||||||
String[] cmd;
|
String[] cmd;
|
||||||
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
||||||
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
||||||
exec = "\"" + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
exec = '"' + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + "\"";
|
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + '"';
|
||||||
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||||
} else {
|
} else {
|
||||||
cmd = new String[]{"sh", "-lc", exec};
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
public void log(String line) {
|
private void log(String line) {
|
||||||
if (started) {
|
if (started) {
|
||||||
String msg = line;
|
String msg = line;
|
||||||
Level level;
|
Level level;
|
||||||
@ -134,12 +120,18 @@ public class ExternalSubLogger extends SubLogger {
|
|||||||
writer.println(line);
|
writer.println(line);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
gc++;
|
|
||||||
gc();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the External Logger Address
|
||||||
|
*
|
||||||
|
* @return External Address
|
||||||
|
*/
|
||||||
|
public UUID getExternalAddress() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerFilter(SubLogFilter filter) {
|
public void registerFilter(SubLogFilter filter) {
|
||||||
if (Util.isNull(filter)) throw new NullPointerException();
|
if (Util.isNull(filter)) throw new NullPointerException();
|
||||||
|
@ -78,57 +78,7 @@ public class InternalSubLogger extends SubLogger {
|
|||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||||
String line;
|
String line;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
if (!line.startsWith(">")) {
|
log(line);
|
||||||
String msg = line;
|
|
||||||
Level level;
|
|
||||||
|
|
||||||
// REGEX Formatting
|
|
||||||
String type = "";
|
|
||||||
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)").matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
|
|
||||||
while (matcher.find()) {
|
|
||||||
type = matcher.group(3).toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)", "");
|
|
||||||
|
|
||||||
// Determine LOG LEVEL
|
|
||||||
switch (type) {
|
|
||||||
case "WARNING":
|
|
||||||
case "WARN":
|
|
||||||
level = Level.WARNING;
|
|
||||||
break;
|
|
||||||
case "SEVERE":
|
|
||||||
case "ERROR":
|
|
||||||
case "ERR":
|
|
||||||
level = Level.SEVERE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
level = Level.INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter Message
|
|
||||||
boolean allow = log.get() && (!SubAPI.getInstance().getInternals().canSudo || SubAPI.getInstance().getInternals().sudo == null || SubAPI.getInstance().getInternals().sudo == getHandler());
|
|
||||||
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
|
|
||||||
filters.addAll(this.filters);
|
|
||||||
for (SubLogFilter filter : filters)
|
|
||||||
try {
|
|
||||||
allow = (filter.log(level, msg) && allow);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log to CONSOLE
|
|
||||||
if (allow) ProxyServer.getInstance().getLogger().log(level, name + " > " + msg);
|
|
||||||
|
|
||||||
// Log to FILE
|
|
||||||
if (writer != null) {
|
|
||||||
writer.println(line);
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
gc++;
|
|
||||||
gc();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {} finally {
|
} catch (IOException e) {} finally {
|
||||||
if (isErr) {
|
if (isErr) {
|
||||||
@ -141,6 +91,57 @@ public class InternalSubLogger extends SubLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void log(String line) {
|
||||||
|
if (!line.startsWith(">")) {
|
||||||
|
String msg = line;
|
||||||
|
Level level;
|
||||||
|
|
||||||
|
// REGEX Formatting
|
||||||
|
String type = "";
|
||||||
|
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)").matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
|
||||||
|
while (matcher.find()) {
|
||||||
|
type = matcher.group(3).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)", "");
|
||||||
|
|
||||||
|
// Determine LOG LEVEL
|
||||||
|
switch (type) {
|
||||||
|
case "WARNING":
|
||||||
|
case "WARN":
|
||||||
|
level = Level.WARNING;
|
||||||
|
break;
|
||||||
|
case "SEVERE":
|
||||||
|
case "ERROR":
|
||||||
|
case "ERR":
|
||||||
|
level = Level.SEVERE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
level = Level.INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter Message
|
||||||
|
boolean allow = log.get() && (!SubAPI.getInstance().getInternals().canSudo || SubAPI.getInstance().getInternals().sudo == null || SubAPI.getInstance().getInternals().sudo == getHandler());
|
||||||
|
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
|
||||||
|
filters.addAll(this.filters);
|
||||||
|
for (SubLogFilter filter : filters)
|
||||||
|
try {
|
||||||
|
allow = (filter.log(level, msg) && allow);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log to CONSOLE
|
||||||
|
if (allow) ProxyServer.getInstance().getLogger().log(level, name + " > " + msg);
|
||||||
|
|
||||||
|
// Log to FILE
|
||||||
|
if (writer != null) {
|
||||||
|
writer.println(line);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (out != null) out.interrupt();
|
if (out != null) out.interrupt();
|
||||||
|
@ -4,17 +4,6 @@ package net.ME1312.SubServers.Bungee.Host;
|
|||||||
* SubLogger Layout Class
|
* SubLogger Layout Class
|
||||||
*/
|
*/
|
||||||
public abstract class SubLogger {
|
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
|
* 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.Client;
|
||||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -25,7 +26,10 @@ public class PacketInExLogMessage implements PacketIn {
|
|||||||
public void execute(Client client, YAMLSection data) {
|
public void execute(Client client, YAMLSection data) {
|
||||||
try {
|
try {
|
||||||
if (data.contains("h") && data.contains("m") && data.getRawString("m").length() != 0 && loggers.keySet().contains(UUID.fromString(data.getRawString("h")))) {
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -19,8 +19,8 @@ public class Executable {
|
|||||||
String[] cmd;
|
String[] cmd;
|
||||||
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
||||||
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
||||||
exec = "\"" + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
exec = '"' + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + "\"";
|
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + '"';
|
||||||
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||||
} else {
|
} else {
|
||||||
cmd = new String[]{"sh", "-lc", exec};
|
cmd = new String[]{"sh", "-lc", exec};
|
||||||
|
@ -17,7 +17,6 @@ import java.util.regex.Pattern;
|
|||||||
* Internal Process Logger Class
|
* Internal Process Logger Class
|
||||||
*/
|
*/
|
||||||
public class SubLogger {
|
public class SubLogger {
|
||||||
public static final int MAX_GC = Integer.getInteger("subservers.logging.max_gc", 4096);
|
|
||||||
protected Process process;
|
protected Process process;
|
||||||
private Object handle;
|
private Object handle;
|
||||||
protected final Logger logger;
|
protected final Logger logger;
|
||||||
@ -50,17 +49,6 @@ public class SubLogger {
|
|||||||
this.file = file;
|
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
|
* Start Logger
|
||||||
*/
|
*/
|
||||||
@ -83,55 +71,12 @@ public class SubLogger {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void start(InputStream in, boolean isErr) {
|
private void start(InputStream in, boolean isErr) {
|
||||||
try {
|
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));
|
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||||
String line;
|
String line;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
if (!line.startsWith(">")) {
|
log(line, network, console);
|
||||||
String msg = line;
|
|
||||||
LogStream level;
|
|
||||||
|
|
||||||
// REGEX Formatting
|
|
||||||
String type = "";
|
|
||||||
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)").matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
|
|
||||||
while (matcher.find()) {
|
|
||||||
type = matcher.group(3).toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)", "");
|
|
||||||
|
|
||||||
// Determine LOG LEVEL
|
|
||||||
switch (type) {
|
|
||||||
case "WARNING":
|
|
||||||
case "WARN":
|
|
||||||
level = logger.warn;
|
|
||||||
break;
|
|
||||||
case "SEVERE":
|
|
||||||
level = logger.severe;
|
|
||||||
break;
|
|
||||||
case "ERROR":
|
|
||||||
case "ERR":
|
|
||||||
level = logger.error;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
level = logger.info;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log to NETWORK
|
|
||||||
if (log.get() && yaml.getBoolean("Network-Log", true)) SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketOutExLogMessage(address, line));
|
|
||||||
|
|
||||||
// Log to CONSOLE
|
|
||||||
if (log.get() && yaml.getBoolean("Console-Log", true)) level.println(TextColor.convertColor(msg));
|
|
||||||
|
|
||||||
// Log to FILE
|
|
||||||
if (writer != null) {
|
|
||||||
writer.println(line);
|
|
||||||
writer.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
gc++;
|
|
||||||
gc();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {} finally {
|
} catch (IOException e) {} finally {
|
||||||
if (isErr) {
|
if (isErr) {
|
||||||
@ -144,6 +89,51 @@ public class SubLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void log(String line, boolean network, boolean console) {
|
||||||
|
if (!line.startsWith(">")) {
|
||||||
|
String msg = line;
|
||||||
|
LogStream level;
|
||||||
|
|
||||||
|
// REGEX Formatting
|
||||||
|
String type = "";
|
||||||
|
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)").matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
|
||||||
|
while (matcher.find()) {
|
||||||
|
type = matcher.group(3).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)", "");
|
||||||
|
|
||||||
|
// Determine LOG LEVEL
|
||||||
|
switch (type) {
|
||||||
|
case "WARNING":
|
||||||
|
case "WARN":
|
||||||
|
level = logger.warn;
|
||||||
|
break;
|
||||||
|
case "SEVERE":
|
||||||
|
level = logger.severe;
|
||||||
|
break;
|
||||||
|
case "ERROR":
|
||||||
|
case "ERR":
|
||||||
|
level = logger.error;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
level = logger.info;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log to NETWORK
|
||||||
|
if (log.get() && network) SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketOutExLogMessage(address, line));
|
||||||
|
|
||||||
|
// Log to CONSOLE
|
||||||
|
if (log.get() && console) level.println(TextColor.convertColor(msg));
|
||||||
|
|
||||||
|
// Log to FILE
|
||||||
|
if (writer != null) {
|
||||||
|
writer.println(line);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop Logger
|
* Stop Logger
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user