Cleanup: Properly log errors

This commit is contained in:
Phoenix616 2023-03-01 18:27:04 +01:00
parent 7a09c53bde
commit 92a013dd10
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
8 changed files with 24 additions and 18 deletions

View File

@ -1,9 +1,10 @@
package com.Acrobot.Breeze.Configuration;
import com.Acrobot.Breeze.Configuration.Annotations.ConfigurationComment;
import com.Acrobot.Breeze.Configuration.Annotations.Parser;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Acrobot
@ -29,7 +30,7 @@ public class FieldParser {
try {
builder.append(field.getName()).append(": ").append(parser.parseToYAML(field.get(null)));
} catch (IllegalAccessException e) {
e.printStackTrace();
Logger.getLogger("FieldParser").log(Level.SEVERE, "Error while parsing field", e);
return "";
}

View File

@ -1,8 +1,12 @@
package com.Acrobot.Breeze.Database;
import com.Acrobot.ChestShop.ChestShop;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Entity;
@ -60,7 +64,7 @@ public class Database {
try {
table.create(fields);
} catch (SQLException e) {
e.printStackTrace();
Logger.getLogger("Database").log(Level.SEVERE, "Error while creating database from " + clazz.getName() + " (" + fields + ")", e);
return false;
}

View File

@ -1,6 +1,8 @@
package com.Acrobot.Breeze.Database;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A class representing a Row in SQL query
@ -85,21 +87,16 @@ public class Row {
try {
object = clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
return null;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException | IllegalAccessException e) {
Logger.getLogger("Row").log(Level.SEVERE, "Error while creating new instance of class " + clazz.getName() + " for row", e);
return null;
}
for (Map.Entry<String, String> value : values.entrySet()) {
try {
clazz.getDeclaredField(value.getKey()).set(object, value.getValue());
} catch (NoSuchFieldException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (NoSuchFieldException | IllegalAccessException ex) {
Logger.getLogger("Row").log(Level.SEVERE, "Error while setting field " + value.getKey() + " to " + value.getValue() + " of class " + clazz.getName(), ex);
}
}

View File

@ -137,7 +137,7 @@ public class Migrations {
try {
items.executeRawNoArgs("INSERT INTO `items` (id, code) SELECT id, code uuid FROM `items-old`");
} catch (SQLException e) {
e.printStackTrace();
ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while inserting items into new database while migrating to v4", e);
}
ChestShop.getBukkitLogger().log(Level.INFO, "Migration of items table finished in " + (System.currentTimeMillis() - start) / 1000.0 + "s!");

View File

@ -17,6 +17,7 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
@ -44,7 +45,7 @@ public class DiscountModule implements Listener {
try {
config.save(ChestShop.loadFile("discounts.yml"));
} catch (IOException e) {
e.printStackTrace();
ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while loading discounts config", e);
}
groupList = config.getKeys(false);

View File

@ -16,6 +16,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import static com.Acrobot.Breeze.Utils.StringUtil.getMinecraftStringWidth;
@ -51,7 +52,7 @@ public class ItemAliasModule implements Listener {
configuration.options().copyDefaults(true);
configuration.save(ChestShop.loadFile("itemAliases.yml"));
} catch (IOException e) {
e.printStackTrace();
ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while saving item aliases config", e);
}
}

View File

@ -11,6 +11,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.util.logging.Level;
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_CREATE;
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.UNKNOWN_PLAYER;
@ -58,7 +60,7 @@ public class NameChecker implements Listener {
}
}
} catch (Exception e) {
e.printStackTrace();
ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while trying to check account for name " + name + " with player " + player.getName(), e);
}
}
event.setOwnerAccount(account);

View File

@ -43,7 +43,7 @@ public class ItemDatabase {
itemDao = DaoCreator.getDaoAndCreateTable(Item.class);
handleMetadataUpdate();
} catch (SQLException e) {
e.printStackTrace();
ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while loading items database", e);
}
}
@ -59,7 +59,7 @@ public class ItemDatabase {
try {
versionConfig.save(configFile);
} catch (IOException e) {
e.printStackTrace();
ChestShop.getBukkitLogger().log(Level.SEVERE, "Error while updating metadata-version from " + previousVersion + " to " + newVersion, e);
}
} else {
ChestShop.getBukkitLogger().log(Level.WARNING, "Error while updating Item Metadata database! While the plugin will still run it will work less efficiently.");