SteamWar/SpigotCore
Archiviert
13
0

Also log warnings #69

Manuell gemergt
Lixfel hat 1 Commits von logWarnings nach master 2020-11-11 13:29:05 +01:00 zusammengeführt
2 geänderte Dateien mit 48 neuen und 27 gelöschten Zeilen
Nur Änderungen aus Commit c6c101a40f werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,14 +20,16 @@
package de.steamwar.core;
import de.steamwar.sql.SWException;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Core;
import org.apache.logging.log4j.core.*;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.spi.StandardLevel;
@Plugin(name = "ErrorLogger", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
public class ErrorLogger extends AbstractAppender {
@ -53,7 +55,7 @@ public class ErrorLogger extends AbstractAppender {
@Override
public void append(LogEvent logEvent) {
if(logEvent.getLevel().isLessSpecificThan(Level.WARN))
if(logEvent.getLevel().intLevel() > StandardLevel.WARN.intLevel())
return;
SWException.log(logEvent);

Datei anzeigen

@ -23,21 +23,58 @@ import org.apache.logging.log4j.core.LogEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SWException {
private SWException(){}
private static boolean logDisabled = false;
private static final List<String> ignorereasons;
static {
List<String> reasons = new ArrayList<>();
reasons.add("Initializing Legacy Material Support.");
reasons.add("Could not save the list after adding a user.");
reasons.add("Failed to save operators list:");
reasons.add("Block at");
reasons.add("POI data mismatch");
reasons.add("This crash report has been saved to:");
reasons.add("Could not pass event PlayerQuitEvent to WorldEditSUI");
reasons.add("[ViaVersion] Failed to remove injection handler");
reasons.add("Something went wrong upgrading!");
reasons.add("Tried to load unrecognized recipe");
ignorereasons = Collections.unmodifiableList(reasons);
}
public static void log(LogEvent logEvent){
if(logDisabled)
return;
String server = Bukkit.getWorlds().get(0).getName();
StringBuilder stacktrace = new StringBuilder(logEvent.getSource().toString());
String message = logEvent.getMessage().getFormattedMessage();
for(String reason : ignorereasons)
if(message.startsWith(reason))
return;
switch (message) {
case "The server has stopped responding!":
logDisabled = true;
return;
case "------------------------------":
message = "Server stopped responding";
logDisabled = true;
break;
case "Exception stopping the server":
logDisabled = true;
break;
default:
}
StringBuilder stacktrace = new StringBuilder(logEvent.getSource().toString());
Throwable throwable = logEvent.getThrown();
while(throwable != null){
stacktrace.append("\nCaused by ").append(throwable.getMessage());
stacktrace.append("\nCaused by ").append(throwable.getClass().getName()).append(": ").append(throwable.getMessage());
for(StackTraceElement ste : throwable.getStackTrace())
stacktrace.append("\n").append(ste.toString());
@ -46,32 +83,14 @@ public class SWException {
}
String st = stacktrace.toString();
String message = logEvent.getMessage().getFormattedMessage();
if(message.startsWith("Block at") || message.startsWith("POI data mismatch") || st.contains("POI data mismatch"))
return;
else if(message.equals("The server has stopped responding!")){
logDisabled = true;
return;
}else if(message.equals("------------------------------")){
message = "Server stopped responding";
logDisabled = true;
}else if(message.equals("Exception stopping the server")){
logDisabled = true;
}else if(message.startsWith("This crash report has been saved to:") || message.startsWith("Could not pass event PlayerQuitEvent to WorldEditSUI")){
return;
}else if(message.startsWith("[ViaVersion] Failed to remove injection handler") || message.startsWith("Something went wrong upgrading!"))
return;
else if(message.startsWith("Tried to load unrecognized recipe"))
if(st.contains("POI data mismatch"))
return;
message += "\n\n";
message += "\n";
for(Player player : Bukkit.getOnlinePlayers())
message += player.getName() + " ";
SQL.update("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)",
server, message, st);
Bukkit.getWorlds().get(0).getName(), message, st);
}
}