Use the previous log level for ambiguous lines

This commit is contained in:
ME1312 2021-12-01 05:42:55 -05:00
parent 7179911d4c
commit 508c2f7627
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
2 changed files with 57 additions and 44 deletions

View File

@ -94,38 +94,42 @@ public class InternalSubLogger extends SubLogger {
} }
} }
private static final String PATTERN = "^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(DEBUG|MESSAGE|MSG|" + Pattern.quote(Level.INFO.getLocalizedName()) + "|INFO|" + Pattern.quote(Level.WARNING.getLocalizedName()) + "|WARNING|WARN|ERROR|ERR|" + Pattern.quote(Level.SEVERE.getLocalizedName()) + "|SEVERE)\\]?:?(?:\\s*>)?\\s*)"; private Level level = Level.INFO;
private static final String PATTERN = "^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(DEBUG|MESSAGE|MSG|" + Pattern.quote(Level.INFO.getLocalizedName()) + "|INFO|" + Pattern.quote(Level.WARNING.getLocalizedName()) + "|WARNING|WARN|ERROR|ERR|" + Pattern.quote(Level.SEVERE.getLocalizedName()) + "|SEVERE)\\]?(?::|\\s*>)?\\s*)";
private void log(String line) { private void log(String line) {
if (!line.startsWith(">")) { if (!line.startsWith(">")) {
String msg = line; String msg = line;
Level level;
// REGEX Formatting // REGEX Formatting
String type = ""; String type = null;
Matcher matcher = Pattern.compile(PATTERN).matcher(msg.replaceAll("\u001B\\[[;\\d]*m", "")); Matcher matcher = Pattern.compile(PATTERN).matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
while (matcher.find()) { if (matcher.find()) {
type = matcher.group(3).toUpperCase(); type = matcher.group(3).toUpperCase();
} }
msg = msg.replaceAll(PATTERN, ""); msg = msg.replaceAll(PATTERN, "");
// Determine LOG LEVEL // Determine LOG LEVEL
if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) { if (type != null) {
level = Level.WARNING; if (type.equalsIgnoreCase(Level.INFO.getLocalizedName())) {
} else if (type.equalsIgnoreCase(Level.SEVERE.getLocalizedName())) {
level = Level.SEVERE;
} else switch (type) {
case "WARNING":
case "WARN":
level = Level.WARNING;
break;
case "SEVERE":
case "ERROR":
case "ERR":
level = Level.SEVERE;
break;
default:
level = Level.INFO; level = Level.INFO;
} else if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) {
level = Level.WARNING;
} else if (type.equalsIgnoreCase(Level.SEVERE.getLocalizedName())) {
level = Level.SEVERE;
} else switch (type) {
case "WARNING":
case "WARN":
level = Level.WARNING;
break;
case "SEVERE":
case "ERROR":
case "ERR":
level = Level.SEVERE;
break;
default:
level = Level.INFO;
}
} }
log(level, msg); log(level, msg);
@ -162,6 +166,8 @@ public class InternalSubLogger extends SubLogger {
try { try {
if (out != null) out.interrupt(); if (out != null) out.interrupt();
if (err != null) err.interrupt(); if (err != null) err.interrupt();
level = Level.INFO;
if (started) { if (started) {
started = false; started = false;
if (writer != null) { if (writer != null) {

View File

@ -141,6 +141,7 @@ public class SubLoggerImpl {
} }
} }
Process process = this.process; Process process = this.process;
if (level == null) level = logger.info;
if (out == null) (out = new Thread(() -> start(process.getInputStream(), false), SubAPI.getInstance().getAppInfo().getName() + "::Log_Spooler(" + name + ')')).start(); if (out == null) (out = new Thread(() -> start(process.getInputStream(), false), SubAPI.getInstance().getAppInfo().getName() + "::Log_Spooler(" + name + ')')).start();
if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), SubAPI.getInstance().getAppInfo().getName() + "::Error_Spooler(" + name + ')')).start(); if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), SubAPI.getInstance().getAppInfo().getName() + "::Error_Spooler(" + name + ')')).start();
} }
@ -164,44 +165,48 @@ public class SubLoggerImpl {
} }
} }
private static final String PATTERN = "^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|MSG|" + Pattern.quote(Level.INFO.getLocalizedName()) + "|INFO|" + Pattern.quote(Level.WARNING.getLocalizedName()) + "|WARNING|WARN|ERROR|ERR|" + Pattern.quote(Level.SEVERE.getLocalizedName()) + "|SEVERE)\\]?:?(?:\\s*>)?\\s*)"; private LogStream level;
private static final String PATTERN = "^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|MSG|" + Pattern.quote(Level.INFO.getLocalizedName()) + "|INFO|" + Pattern.quote(Level.WARNING.getLocalizedName()) + "|WARNING|WARN|ERROR|ERR|" + Pattern.quote(Level.SEVERE.getLocalizedName()) + "|SEVERE)\\]?(?::|\\s*>)?\\s*)";
private void log(String line) { private void log(String line) {
if (!line.startsWith(">")) { if (!line.startsWith(">")) {
String msg = line; String msg = line;
LogStream level;
// REGEX Formatting // REGEX Formatting
String type = ""; String type = null;
Matcher matcher = Pattern.compile(PATTERN).matcher(msg.replaceAll("\u001B\\[[;\\d]*m", "")); Matcher matcher = Pattern.compile(PATTERN).matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
while (matcher.find()) { if (matcher.find()) {
type = matcher.group(3).toUpperCase(); type = matcher.group(3).toUpperCase();
} }
msg = msg.replaceAll(PATTERN, ""); msg = msg.replaceAll(PATTERN, "");
// Determine LOG LEVEL // Determine LOG LEVEL
if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) { if (type != null) {
level = logger.warn; if (type.equalsIgnoreCase(Level.INFO.getLocalizedName())) {
} else if (type.equalsIgnoreCase(Level.SEVERE.getLocalizedName())) {
level = logger.severe;
} else switch (type) {
case "WARNING":
case "WARN":
level = logger.warn;
break;
case "SEVERE":
level = logger.severe;
break;
case "ERROR":
case "ERR":
level = logger.error;
break;
case "MSG":
case "MESSAGE":
level = logger.message;
break;
default:
level = logger.info; level = logger.info;
} else if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) {
level = logger.warn;
} else if (type.equalsIgnoreCase(Level.SEVERE.getLocalizedName())) {
level = logger.severe;
} else switch (type) {
case "WARNING":
case "WARN":
level = logger.warn;
break;
case "SEVERE":
level = logger.severe;
break;
case "ERROR":
case "ERR":
level = logger.error;
break;
case "MSG":
case "MESSAGE":
level = logger.message;
break;
default:
level = logger.info;
}
} }
// Log to FILTER // Log to FILTER
@ -222,6 +227,8 @@ public class SubLoggerImpl {
try { try {
if (out != null) out.interrupt(); if (out != null) out.interrupt();
if (err != null) err.interrupt(); if (err != null) err.interrupt();
level = null;
if (started) { if (started) {
started = false; started = false;
if (writer != null) { if (writer != null) {