Skip to content

Commit 4023908

Browse files
committed
Fix a few issues with debug logging
Also add a warning if the updater section is missing
1 parent cc362a1 commit 4023908

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

modules/API/src/main/java/com/comphenix/protocol/ProtocolConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ private void loadSections(boolean copyDefaults) {
157157
}
158158
if (global != null) {
159159
updater = global.getConfigurationSection(SECTION_AUTOUPDATER);
160+
if (updater.getValues(true).isEmpty()) {
161+
plugin.getLogger().warning("Updater section is missing, regenerate your config!");
162+
}
160163
}
161164

162165
// Automatically copy defaults

modules/API/src/main/java/com/comphenix/protocol/ProtocolLibrary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ protected static void init(Plugin plugin, ProtocolConfig config, ProtocolManager
7171
ProtocolLibrary.reporter = reporter;
7272
ProtocolLibrary.executorAsync = executorAsync;
7373
ProtocolLibrary.executorSync = executorSync;
74-
ProtocolLogger.init(plugin);
7574
initialized = true;
7675
}
7776

modules/API/src/main/java/com/comphenix/protocol/ProtocolLogger.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@
1818

1919
import java.text.MessageFormat;
2020
import java.util.logging.Level;
21-
import java.util.logging.Logger;
2221

2322
import org.bukkit.plugin.Plugin;
2423

2524
/**
2625
* @author dmulloy2
2726
*/
2827
public class ProtocolLogger {
29-
private static Logger logger;
28+
private static Plugin plugin;
3029

3130
protected static void init(Plugin plugin) {
32-
ProtocolLogger.logger = plugin.getLogger();
31+
ProtocolLogger.plugin = plugin;
3332
}
3433

3534
private static boolean isDebugEnabled() {
3635
try {
37-
return ProtocolLibrary.getConfig().isDebug();
38-
} catch (Throwable ex) {
39-
return true; // For testing
36+
return plugin.getConfig().getBoolean("global.debug", false);
37+
} catch (Throwable ex) { // Maybe we're testing or something
38+
return false;
4039
}
4140
}
4241

@@ -47,7 +46,7 @@ private static boolean isDebugEnabled() {
4746
* @param args Arguments to format in
4847
*/
4948
public static void log(Level level, String message, Object... args) {
50-
logger.log(level, MessageFormat.format(message, args));
49+
plugin.getLogger().log(level, MessageFormat.format(message, args));
5150
}
5251

5352
/**
@@ -66,16 +65,12 @@ public static void log(String message, Object... args) {
6665
* @param ex Exception to log
6766
*/
6867
public static void log(Level level, String message, Throwable ex) {
69-
logger.log(level, message, ex);
68+
plugin.getLogger().log(level, message, ex);
7069
}
7170

7271
public static void debug(String message, Object... args) {
7372
if (isDebugEnabled()) {
74-
if (logger != null) {
75-
log("[Debug] " + message, args);
76-
} else {
77-
System.out.println("[Debug] " + MessageFormat.format(message, args));
78-
}
73+
log("[Debug] " + message, args);
7974
}
8075
}
8176
}

modules/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLib.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ private enum ProtocolCommand {
148148

149149
@Override
150150
public void onLoad() {
151-
// Load configuration
151+
// Logging
152152
logger = getLoggerSafely();
153+
ProtocolLogger.init(this);
154+
153155
Application.registerPrimaryThread();
154156

155157
// Initialize enhancer factory

0 commit comments

Comments
 (0)