Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Static is optional, depending on how you like to make your Objects. VARIABLES throwable: The exception, severity: How much of a concern this error should be.
- //customReason: Add some additional notes for yourself to help your fix the error. logToConsole: Log the stacktrace to console along with logging to file,
- //logFullyToConsole: logToConsole must be true. Logs the full detailed report to console, along with writing it to the file.
- //notifyAdmin: If the error is such a factor, set this to true, and it will send a message to all online admin a suppressed detailed report.
- //Permission node for admin to see the message is error.notify.
- public /*static*/ void logError(Plugin plugin, Throwable throwable, String severity, String customReason, boolean logToConsole, boolean logFullyToConsole, boolean notifyAdmin){
- String date = new java.text.SimpleDateFormat("MM_dd_yyyy-HH:mm:ss").format(new java.util.Date (System.currentTimeMillis()));
- if(notifyAdmin){
- Iterator<ProxiedPlayer> ppi = BungeeCord.getInstance().getPlayers().iterator();
- while(ppi.hasNext()){
- ProxiedPlayer pp = ppi.next();
- if(pp instanceof ProxiedPlayer){
- if(pp.hasPermission("error.notify")){
- pp.sendMessage(ChatColor.RED + "--------SEVERE BUNGEE ERROR------");
- pp.sendMessage(ChatColor.RED + "CAUSE: " + plugin.getDescription().getName());
- pp.sendMessage(ChatColor.RED + "DEV INFO: " + customReason);
- for(int i = 0; i < throwable.getStackTrace().length; i++){
- pp.sendMessage(ChatColor.RED + "" + throwable.getStackTrace()[i]);
- }
- }
- }
- }
- }
- if(logToConsole && !logFullyToConsole){
- throwable.printStackTrace();
- }
- if(logFullyToConsole && logToConsole){
- System.out.println("================================================");
- System.out.println("-----------General Info--------------");
- System.out.println("Error caused by: " + plugin.getDescription().getName());
- String[] pro = {"java.version", "java.vm.version", "java.runtime.version"};
- Properties properties = System.getProperties();
- for (int i = 0; i < pro.length; i++) {
- System.out.println(pro[i] + ": " + properties.getProperty(pro[i]));
- }
- System.out.println("Unix Time of Error: " + System.currentTimeMillis());
- System.out.println("Formatted Time of Error: " + date);
- System.out.println();
- System.out.println("-----------Instance Info-------------");
- System.out.println("BungeeCord Version: " + BungeeCord.getInstance().getVersion());
- System.out.println("Online State: " + BungeeCord.getInstance().config.isOnlineMode());
- System.out.println("Number of players online: " + BungeeCord.getInstance().getPlayers().size());
- System.out.println("Protocol Version: " + BungeeCord.getInstance().getProtocolVersion());
- System.out.println("Plugin List: (" + BungeeCord.getInstance().getPluginManager().getPlugins().size() + ")");
- Iterator<Plugin> pli = BungeeCord.getInstance().getPluginManager().getPlugins().iterator();
- while(pli.hasNext()){
- Plugin pl = pli.next();
- System.out.println("- " + pl.getDescription().getName() + " - " + pl.getDescription().getVersion());
- }
- System.out.println();
- System.out.println("-----------Developers Notes-------------");
- System.out.println(customReason);
- System.out.println();
- System.out.println("-----------Stacktrace-------------");
- for(int i = 0; i < throwable.getStackTrace().length; i++){
- System.out.println(throwable.getStackTrace()[i]);
- }
- System.out.println("-----------Suppressed Stacktrace-------------");
- for(int i = 0; i < throwable.getSuppressed().length; i++){
- System.out.println(throwable.getSuppressed()[i]);
- }
- System.out.println("-----------Cause (Usually null)-------------");
- System.out.println(throwable.getCause());
- System.out.println();
- System.out.println();
- System.out.println("-----------LocalizedMessage (Usually null)-------------");
- System.out.println(throwable.getLocalizedMessage());
- System.out.println();
- System.out.println("-----------Message (Usually null)------------------");
- System.out.println(throwable.getMessage());
- System.out.println();
- System.out.println("-----------End Error---------------");
- System.out.println();
- }
- System.out.println("[" + severity + "]" + " The plugin: " + plugin.getDescription().getName() + " has thrown an internal exception! This error has been logged in: " + "plugins/errors/" + plugin.getDescription().getName() + "/error_on_" + date + ".log"
- + " Do not wait for the version this is fixed in! Hurry and report it to " + plugin.getDescription().getAuthor() + " on the SpigotMC.org forums!");
- File errorFile = new File("plugins/errors/" + plugin.getDescription().getName() + "/error_on_" + date + ".log");
- try {
- File dir = new File("plugins/errors/" + plugin.getDescription().getName() + "/");
- dir.mkdirs();
- errorFile.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- System.out.println("An internal exception was caused by an Error Logging!! Not good man. Not good.");
- }
- try {
- PrintWriter writer = new PrintWriter(new FileWriter(errorFile,true));
- writer.println("================================================");
- writer.println("-----------General Info--------------");
- writer.println("Error caused by: + plugin.getDescription().getName());
- String[] pro = {"java.version", "java.vm.version", "java.runtime.version"};
- Properties properties = System.getProperties();
- for (int i = 0; i < pro.length; i++) {
- writer.println(pro[i] + ": " + properties.getProperty(pro[i]));
- }
- writer.println("Unix Time of Error: " + System.currentTimeMillis());
- writer.println("Formatted Time of Error: " + date);
- writer.println();
- writer.println("-----------Instance Info-------------");
- writer.println("BungeeCord Version: " + BungeeCord.getInstance().getVersion());
- writer.println("Online State: " + BungeeCord.getInstance().config.isOnlineMode());
- writer.println("Number of players online: " + BungeeCord.getInstance().getPlayers().size());
- writer.println("Protocol Version: " + BungeeCord.getInstance().getProtocolVersion());
- writer.println("Plugin List: (" + BungeeCord.getInstance().getPluginManager().getPlugins().size() + ")");
- Iterator<Plugin> pli = BungeeCord.getInstance().getPluginManager().getPlugins().iterator();
- while(pli.hasNext()){
- Plugin pl = pli.next();
- writer.println("- " + pl.getDescription().getName() + " - " + pl.getDescription().getVersion());
- }
- writer.println();
- writer.println("-----------Developers Notes-------------");
- writer.println(customReason);
- writer.println();
- writer.println("-----------Stacktrace-------------");
- for(int i = 0; i < throwable.getStackTrace().length; i++){
- writer.println(throwable.getStackTrace()[i]);
- }
- writer.println("-----------Suppressed Stacktrace-------------");
- for(int i = 0; i < throwable.getSuppressed().length; i++){
- writer.println(throwable.getSuppressed()[i]);
- }
- writer.println("-----------Cause (Usually null)-------------");
- writer.println(throwable.getCause());
- writer.println();
- writer.println();
- writer.println("-----------LocalizedMessage (Usually null)-------------");
- writer.println(throwable.getLocalizedMessage());
- writer.println();
- writer.println("-----------Message (Usually null)------------------");
- writer.println(throwable.getMessage());
- writer.println();
- writer.println("-----------End Error---------------");
- writer.println();
- writer.close();
- } catch(Exception e){
- e.printStackTrace();
- System.out.println("An internal exception was caused by an Error Logging!! Not good man. Not good.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement