All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.plugin.PluginLogger Maven / Gradle / Ivy

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 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 Logger}.
 *
 * @see Logger
 */
public class PluginLogger extends Logger {
  private final String pluginName;

  /**
   * Creates a new PluginLogger that extracts the name from a plugin.
   *
   * @param context A reference to the plugin
   */
  public PluginLogger(Plugin context) {
    super(context.getClass().getCanonicalName(), null);
    String prefix = context.getDescription().getPrefix();
    pluginName = prefix != null ? "[" + prefix + "] " : "[" + context.getDescription().getName() + "] ";
    setParent(context.getServer().getLogger());
    setLevel(Level.ALL);
  }

  @Override
  public void log(LogRecord logRecord) {
    logRecord.setMessage(pluginName + logRecord.getMessage());
    super.log(logRecord);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy