Add per plugin loggers

This commit is contained in:
mickare 2013-05-14 11:19:01 +10:00 committed by md_5
parent 0afefa8f61
commit aefe3333a9
2 changed files with 29 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package net.md_5.bungee.api.plugin;
import java.io.File;
import java.io.InputStream;
import java.util.logging.Logger;
import lombok.Getter;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ConfigurationAdapter;
@ -19,6 +20,8 @@ public class Plugin
private ProxyServer proxy;
@Getter
private File file;
@Getter
private Logger logger;
/**
* Called when the plugin has just been loaded. Most of the proxy will not
@ -78,5 +81,6 @@ public class Plugin
this.proxy = proxy;
this.description = description;
this.file = file;
this.logger = new PluginLogger(this);
}
}

View File

@ -0,0 +1,25 @@
package net.md_5.bungee.api.plugin;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import net.md_5.bungee.api.ProxyServer;
public class PluginLogger extends Logger
{
private String pluginName;
protected PluginLogger(Plugin plugin)
{
super( plugin.getClass().getCanonicalName(), null );
pluginName = "[" + plugin.getDescription().getName() + "] ";
setParent( ProxyServer.getInstance().getLogger() );
}
@Override
public void log(LogRecord logRecord)
{
logRecord.setMessage( pluginName + logRecord.getMessage() );
super.log( logRecord );
}
}