Updated logging to mostly use java.util.logging.Logger [SD-8645]

This commit is contained in:
Christian Koop 2021-08-29 13:49:01 +02:00
parent 3d8a08508a
commit 03e2360a98
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
6 changed files with 29 additions and 19 deletions

View File

@ -1237,7 +1237,7 @@ public enum CompatibleSound {
} }
} }
if (DEBUG && find == null) { if (DEBUG && find == null) {
System.out.println("Sound for " + name() + " Not found!"); System.err.println("Sound for " + name() + " not found!");
} }
sound = find; sound = find;
compatibilityMode = find == null; compatibilityMode = find == null;
@ -1253,7 +1253,7 @@ public enum CompatibleSound {
sound = Sound.valueOf(name()); sound = Sound.valueOf(name());
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("ERROR loading " + name()); System.err.println("ERROR loading " + name());
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -1268,9 +1268,9 @@ public enum CompatibleSound {
} }
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("ERROR loading " + name()); System.err.println("ERROR loading " + name());
for (Version v : versions) { for (Version v : versions) {
System.out.println(v.version + " - " + v.sound); System.err.println(v.version + " - " + v.sound);
} }
e.printStackTrace(); e.printStackTrace();
} }
@ -1303,9 +1303,9 @@ public enum CompatibleSound {
compatibilityMode = false; compatibilityMode = false;
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("ERROR loading " + name() + " (" + minVersion); System.err.println("ERROR loading " + name() + " (" + minVersion);
for (Version v : versions) { for (Version v : versions) {
System.out.println(v.version + " - " + v.sound); System.err.println(v.version + " - " + v.sound);
} }
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -39,10 +39,10 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
public class SongodaCore { public class SongodaCore {
private final static Logger logger = Logger.getLogger("SongodaCore");
private final static String prefix = "[SongodaCore]";
/** /**
* Whenever we make a major change to the core GUI, updater, * Whenever we make a major change to the core GUI, updater,
@ -197,7 +197,7 @@ public class SongodaCore {
private ArrayList<BukkitTask> tasks = new ArrayList(); private ArrayList<BukkitTask> tasks = new ArrayList();
private void register(JavaPlugin plugin, int pluginID, String icon, String libraryVersion) { private void register(JavaPlugin plugin, int pluginID, String icon, String libraryVersion) {
System.out.println(getPrefix() + "Hooked " + plugin.getName() + "."); logger.info(getPrefix() + "Hooked " + plugin.getName() + ".");
PluginInfo info = new PluginInfo(plugin, pluginID, icon, libraryVersion); PluginInfo info = new PluginInfo(plugin, pluginID, icon, libraryVersion);
// don't forget to check for language pack updates ;) // don't forget to check for language pack updates ;)
info.addModule(new LocaleModule()); info.addModule(new LocaleModule());
@ -240,9 +240,9 @@ public class SongodaCore {
} }
} catch (IOException e) { } catch (IOException e) {
final String er = e.getMessage(); final String er = e.getMessage();
System.out.println("Connection with Songoda servers failed: " + (er.contains("URL") ? er.substring(0, er.indexOf("URL") + 3) : er)); logger.log(Level.FINE, "Connection with Songoda servers failed: " + (er.contains("URL") ? er.substring(0, er.indexOf("URL") + 3) : er));
} catch (ParseException e) { } catch (ParseException e) {
System.out.println("Failed to parse json for " + plugin.getJavaPlugin().getName() + " update check"); logger.log(Level.FINE, "Failed to parse json for " + plugin.getJavaPlugin().getName() + " update check");
} }
} }
@ -263,7 +263,11 @@ public class SongodaCore {
} }
public static String getPrefix() { public static String getPrefix() {
return prefix + " "; return "[SongodaCore] ";
}
public static Logger getLogger() {
return logger;
} }
public static boolean isRegistered(String plugin) { public static boolean isRegistered(String plugin) {

View File

@ -1,10 +1,12 @@
package com.songoda.core.configuration; package com.songoda.core.configuration;
import com.songoda.core.SongodaCore;
import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleMaterial;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
import java.util.logging.Level;
public class ConfigSetting { public class ConfigSetting {
@ -111,7 +113,7 @@ public class ConfigSetting {
CompatibleMaterial mat = CompatibleMaterial.getMaterial(config.getString(key)); CompatibleMaterial mat = CompatibleMaterial.getMaterial(config.getString(key));
if (mat == null) { if (mat == null) {
System.out.println(String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val)); SongodaCore.getLogger().log(Level.WARNING, String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
} }
return mat != null ? mat : CompatibleMaterial.STONE; return mat != null ? mat : CompatibleMaterial.STONE;
@ -124,7 +126,7 @@ public class ConfigSetting {
CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null; CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
if (mat == null) { if (mat == null) {
System.out.println(String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val)); SongodaCore.getLogger().log(Level.WARNING, String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
} }
return mat != null ? mat : def; return mat != null ? mat : def;

View File

@ -1,5 +1,6 @@
package com.songoda.core.database; package com.songoda.core.database;
import com.songoda.core.SongodaCore;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -16,7 +17,7 @@ public class MySQLConnector implements DatabaseConnector {
public MySQLConnector(Plugin plugin, String hostname, int port, String database, String username, String password, boolean useSSL) { public MySQLConnector(Plugin plugin, String hostname, int port, String database, String username, String password, boolean useSSL) {
this.plugin = plugin; this.plugin = plugin;
System.out.println("connecting to " + hostname + " : " + port); plugin.getLogger().info("connecting to " + hostname + " : " + port);
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?useSSL=" + useSSL); config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?useSSL=" + useSSL);

View File

@ -1,5 +1,6 @@
package com.songoda.core.utils; package com.songoda.core.utils;
import com.songoda.core.SongodaCore;
import com.songoda.core.compatibility.ClassMapping; import com.songoda.core.compatibility.ClassMapping;
import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.compatibility.ServerVersion;
import org.bukkit.Effect; import org.bukkit.Effect;
@ -137,7 +138,6 @@ public class BlockUtilsModern {
Object mblock = nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(cblock)); Object mblock = nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(cblock));
Object mpos = craftBlock_getPostition.invoke(cblock); Object mpos = craftBlock_getPostition.invoke(cblock);
//System.out.println(mblock.getClass());
// now for testing stuff // now for testing stuff
if (clazzLeverBlock.isAssignableFrom(mblock.getClass())) { if (clazzLeverBlock.isAssignableFrom(mblock.getClass())) {
final Object mstate = craftBlockData_getState.invoke(block.getBlockData()); final Object mstate = craftBlockData_getState.invoke(block.getBlockData());
@ -148,7 +148,7 @@ public class BlockUtilsModern {
} else if (clazzPressurePlateBlock.isAssignableFrom(mblock.getClass())) { } else if (clazzPressurePlateBlock.isAssignableFrom(mblock.getClass())) {
nmsPlate_updateNeighbours.invoke(mblock, mworld, mpos); nmsPlate_updateNeighbours.invoke(mblock, mworld, mpos);
} else { } else {
System.out.println("Unknown redstone: " + mblock.getClass().getName()); SongodaCore.getLogger().warning("Unknown redstone: " + mblock.getClass().getName());
} }
// //
// if(mblock instanceof net.minecraft.server.v1_15_R1.BlockLever) { // if(mblock instanceof net.minecraft.server.v1_15_R1.BlockLever) {

View File

@ -1,5 +1,7 @@
package com.songoda.core.utils; package com.songoda.core.utils;
import com.songoda.core.SongodaCore;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
@ -23,6 +25,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -152,7 +155,7 @@ public class ReflectionUtils {
Class<?> loadedClazz = Class.forName(name.substring(0, name.lastIndexOf('.')).replace('/', '.')); Class<?> loadedClazz = Class.forName(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
packageClasses.add(loadedClazz); packageClasses.add(loadedClazz);
} catch (ClassNotFoundException e1) { } catch (ClassNotFoundException e1) {
System.err.println("class not found: " + e1.getMessage()); SongodaCore.getLogger().log(Level.FINE, "class not found: " + e1.getMessage());
} }
} }
} }
@ -179,7 +182,7 @@ public class ReflectionUtils {
packageClasses.add(loadedClazz); packageClasses.add(loadedClazz);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
System.err.println("class not found: " + e.getMessage()); SongodaCore.getLogger().log(Level.FINE, "class not found: " + e.getMessage());
} }
} }
return super.visitFile(file, attrs); return super.visitFile(file, attrs);