SteamWar/BungeeCore
Archiviert
13
2

Adding /bug and automated [ERROR] logging #60

Manuell gemergt
Lixfel hat 1 Commits von bugTracking nach master 2020-02-11 17:47:54 +01:00 zusammengeführt
4 geänderte Dateien mit 85 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -52,6 +52,7 @@ public class BungeeCore extends Plugin {
setInstance(this);
loadConfig();
new ErrorLogger();
new ConnectionListener();
new Forge();
new LabyMod();
@ -101,6 +102,7 @@ public class BungeeCore extends Plugin {
@Override
public void onDisable(){
ErrorLogger.stop();
SQL.close();
}

Datei anzeigen

@ -0,0 +1,50 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.SWException;
import net.md_5.bungee.api.ProxyServer;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
public class ErrorLogger extends Handler {
private static ErrorLogger instance;
ErrorLogger(){
ProxyServer.getInstance().getLogger().addHandler(this);
instance = this;
}
static void stop(){
ProxyServer.getInstance().getLogger().removeHandler(instance);
}
@Override
public void publish(LogRecord record) {
if(record.getLevel() != Level.SEVERE)
return;
StringBuilder stacktrace = new StringBuilder(record.getSourceClassName() + "\n" + record.getSourceMethodName());
Throwable thrown = record.getThrown();
while(thrown != null){
stacktrace.append("\nCaused by").append(thrown.getMessage());
for(StackTraceElement ste : thrown.getStackTrace())
stacktrace.append("\n").append(ste.toString());
thrown = thrown.getCause();
}
SWException.log("Bungee", record.getMessage(), stacktrace.toString());
}
@Override
public void flush() {
//ignored
}
@Override
public void close() {
//ignored
}
}

Datei anzeigen

@ -0,0 +1,24 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.sql.SWException;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class BugCommand extends BasicCommand {
public BugCommand() {
super("bug", null);
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
String server = player.getServer().getInfo().getName();
String message = String.join(" ", args);
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
SWException.log(server, message, player.getName() + " " + user.getId());
}
}

Datei anzeigen

@ -0,0 +1,9 @@
package de.steamwar.bungeecore.sql;
public class SWException {
private SWException(){}
public static void log(String server, String message, String stacktrace){
SQL.update("INSERT INTO Exception (server, meassage, stacktrace) VALUES (?, ?, ?)", server, message, stacktrace);
}
}