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,23 +94,26 @@ 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) {
if (!line.startsWith(">")) {
String msg = line;
Level level;
// REGEX Formatting
String type = "";
String type = null;
Matcher matcher = Pattern.compile(PATTERN).matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
while (matcher.find()) {
if (matcher.find()) {
type = matcher.group(3).toUpperCase();
}
msg = msg.replaceAll(PATTERN, "");
// Determine LOG LEVEL
if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) {
if (type != null) {
if (type.equalsIgnoreCase(Level.INFO.getLocalizedName())) {
level = Level.INFO;
} else if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) {
level = Level.WARNING;
} else if (type.equalsIgnoreCase(Level.SEVERE.getLocalizedName())) {
level = Level.SEVERE;
@ -127,6 +130,7 @@ public class InternalSubLogger extends SubLogger {
default:
level = Level.INFO;
}
}
log(level, msg);
@ -162,6 +166,8 @@ public class InternalSubLogger extends SubLogger {
try {
if (out != null) out.interrupt();
if (err != null) err.interrupt();
level = Level.INFO;
if (started) {
started = false;
if (writer != null) {

View File

@ -141,6 +141,7 @@ public class SubLoggerImpl {
}
}
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 (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), SubAPI.getInstance().getAppInfo().getName() + "::Error_Spooler(" + name + ')')).start();
}
@ -164,23 +165,26 @@ 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) {
if (!line.startsWith(">")) {
String msg = line;
LogStream level;
// REGEX Formatting
String type = "";
String type = null;
Matcher matcher = Pattern.compile(PATTERN).matcher(msg.replaceAll("\u001B\\[[;\\d]*m", ""));
while (matcher.find()) {
if (matcher.find()) {
type = matcher.group(3).toUpperCase();
}
msg = msg.replaceAll(PATTERN, "");
// Determine LOG LEVEL
if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) {
if (type != null) {
if (type.equalsIgnoreCase(Level.INFO.getLocalizedName())) {
level = logger.info;
} else if (type.equalsIgnoreCase(Level.WARNING.getLocalizedName())) {
level = logger.warn;
} else if (type.equalsIgnoreCase(Level.SEVERE.getLocalizedName())) {
level = logger.severe;
@ -203,6 +207,7 @@ public class SubLoggerImpl {
default:
level = logger.info;
}
}
// Log to FILTER
if (log.value()) level.println(TextColor.convertColor(msg));
@ -222,6 +227,8 @@ public class SubLoggerImpl {
try {
if (out != null) out.interrupt();
if (err != null) err.interrupt();
level = null;
if (started) {
started = false;
if (writer != null) {