Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PluginLogger.java
1 package org.bukkit.plugin;
2 
3 import java.util.logging.Level;
4 import java.util.logging.LogRecord;
5 import java.util.logging.Logger;
6 
7 /**
8  * The PluginLogger class is a modified {@link Logger} that prepends all
9  * logging calls with the name of the plugin doing the logging. The API for
10  * PluginLogger is exactly the same as {@link Logger}.
11  *
12  * @see Logger
13  */
14 public class PluginLogger extends Logger {
15  private String pluginName;
16 
17  /**
18  * Creates a new PluginLogger that extracts the name from a plugin.
19  *
20  * @param context A reference to the plugin
21  */
22  public PluginLogger(Plugin context) {
23  super(context.getClass().getCanonicalName(), null);
24  String prefix = context.getDescription().getPrefix();
25  pluginName = prefix != null ? new StringBuilder().append("[").append(prefix).append("] ").toString() : "[" + context.getDescription().getName() + "] ";
26  setParent(context.getServer().getLogger());
27  setLevel(Level.ALL);
28  }
29 
30  @Override
31  public void log(LogRecord logRecord) {
32  logRecord.setMessage(pluginName + logRecord.getMessage());
33  super.log(logRecord);
34  }
35 
36 }
PluginDescriptionFile getDescription()
Logger getLogger()