浏览代码

Add verbose logging option and a debug method to use it.

Closes #609
NuclearW 12 年之前
父节点
当前提交
c805a48a87

+ 1 - 0
src/main/java/com/gmail/nossr50/config/Config.java

@@ -39,6 +39,7 @@ public class Config extends ConfigLoader {
     public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); }
     public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); }
     public boolean getBackupsEnabled() { return config.getBoolean("General.Generate_Backups", true); }
+    public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); }
     public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); }
     public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); }
 

+ 6 - 0
src/main/java/com/gmail/nossr50/mcMMO.java

@@ -51,6 +51,7 @@ import com.gmail.nossr50.skills.runnables.SkillMonitor;
 import com.gmail.nossr50.spout.SpoutConfig;
 import com.gmail.nossr50.spout.SpoutTools;
 import com.gmail.nossr50.util.Permissions;
+import com.gmail.nossr50.util.LogFilter;
 import com.gmail.nossr50.util.UpdateCheck;
 import com.gmail.nossr50.util.Users;
 
@@ -97,6 +98,7 @@ public class mcMMO extends JavaPlugin {
     @Override
     public void onEnable() {
         p = this;
+        getLogger().setFilter(new LogFilter(this));
         entityMetadata = new FixedMetadataValue(mcMMO.p, true);
         setupFilePaths();
         setupSpout();
@@ -451,4 +453,8 @@ public class mcMMO extends JavaPlugin {
     public void toggleXpEventEnabled() {
         xpEventEnabled = !xpEventEnabled;
     }
+
+    public void debug(String message) {
+        getLogger().info("[Debug] " + message);
+    }
 }

+ 25 - 0
src/main/java/com/gmail/nossr50/util/LogFilter.java

@@ -0,0 +1,25 @@
+package com.gmail.nossr50.util;
+
+import java.util.logging.Filter;
+import java.util.logging.LogRecord;
+
+import com.gmail.nossr50.mcMMO;
+
+public class LogFilter implements Filter {
+    private boolean debug;
+
+    public LogFilter(mcMMO plugin) {
+        // Doing a config loading lite here, because we can't depend on the config loader to have loaded before any debug messages are sent
+        debug = plugin.getConfig().getBoolean("General.Verbose_Logging");
+    }
+
+    @Override
+    public boolean isLoggable(LogRecord record) {
+        if(record.getMessage().contains("[Debug]") && !debug) {
+            return false;
+        }
+        else {
+            return true;
+        }
+    }
+}

+ 2 - 0
src/main/resources/config.yml

@@ -22,6 +22,8 @@ General:
     #Allow mcMMO to create zip backups for flatfile data on shutdown.
     Generate_Backups: true
     Power_Level_Cap: 0
+    #Should mcMMO print out debug messages?
+    Verbose_Logging: false
 
 Database_Purging:
     #Amount of time (in hours) to wait between database purging