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

Closes #609
This commit is contained in:
NuclearW 2013-02-20 11:47:08 -05:00
parent 918d81198f
commit c805a48a87
4 changed files with 34 additions and 0 deletions

View File

@ -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); }

View File

@ -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);
}
}

View File

@ -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;
}
}
}

View File

@ -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