[Bleeding] Added Plugin.getLogger() which returns a java.util.Logger that prefixes messages with the plugin name.

Note: the server when enabling or disabling a plugin will now by default log this.

By: rmichela <deltahat@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-12-15 00:31:13 -05:00
parent 81c2625a0e
commit c02d8155ad
5 changed files with 67 additions and 3 deletions

View File

@@ -0,0 +1,34 @@
package org.bukkit.plugin;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
/**
* The PluginLogger class is a modified {@link java.util.logging.Logger} that prepends all logging calls with the name of the
* plugin doing the logging.
*
* The API for PluginLogger is exactly the same as {@link java.util.logging.Logger}.
*/
public class PluginLogger extends Logger {
private String pluginName;
/**
* Creates a new PluginLogger that extracts the name from a plugin.
* @param context
*/
public PluginLogger(Plugin context) {
super(context.getClass().getCanonicalName(), null);
pluginName = "[" + context.getDescription().getName() + "] ";
setParent(context.getServer().getLogger());
setLevel(Level.ALL);
}
@Override
public void log(LogRecord logRecord) {
logRecord.setMessage(pluginName + logRecord.getMessage());
super.log(logRecord);
}
}