    001package net.minecraft.logging;
    002
    003import cpw.mods.fml.common.FMLLog;
    004import cpw.mods.fml.relauncher.Side;
    005import cpw.mods.fml.relauncher.SideOnly;
    006import java.util.logging.ConsoleHandler;
    007import java.util.logging.FileHandler;
    008import java.util.logging.Handler;
    009import java.util.logging.Level;
    010import java.util.logging.Logger;
    011
    012public class LogAgent implements ILogAgent
    013{
    014    private final Logger serverLogger;
    015    private final String logFile;
    016    private final String loggerName;
    017    private final String loggerPrefix;
    018
    019    public LogAgent(String par1Str, String par2Str, String par3Str)
    020    {
    021        this.serverLogger = Logger.getLogger(par1Str);
    022        this.loggerName = par1Str;
    023        this.loggerPrefix = par2Str;
    024        this.logFile = par3Str;
    025        this.setupLogger();
    026    }
    027
    028    /**
    029     * Sets up the logger for usage.
    030     */
    031    private void setupLogger()
    032    {
    033        this.serverLogger.setParent(FMLLog.getLogger());
    034        Handler[] ahandler = this.serverLogger.getHandlers();
    035        int i = ahandler.length;
    036
    037        for (int j = 0; j < i; ++j)
    038        {
    039            Handler handler = ahandler[j];
    040            this.serverLogger.removeHandler(handler);
    041        }
    042
    043        LogFormatter logformatter = new LogFormatter(this, (LogAgentINNER1)null);
    044        try
    045        {
    046            FileHandler filehandler = new FileHandler(this.logFile, true);
    047            filehandler.setFormatter(logformatter);
    048            this.serverLogger.addHandler(filehandler);
    049        }
    050        catch (Exception exception)
    051        {
    052            this.serverLogger.log(Level.WARNING, "Failed to log " + this.loggerName + " to " + this.logFile, exception);
    053        }
    054    }
    055
    056    public void logInfo(String par1Str)
    057    {
    058        this.serverLogger.log(Level.INFO, par1Str);
    059    }
    060
    061    @SideOnly(Side.SERVER)
    062    public Logger getServerLogger()
    063    {
    064        return this.serverLogger;
    065    }
    066
    067    public void logWarning(String par1Str)
    068    {
    069        this.serverLogger.log(Level.WARNING, par1Str);
    070    }
    071
    072    public void logWarningFormatted(String par1Str, Object ... par2ArrayOfObj)
    073    {
    074        this.serverLogger.log(Level.WARNING, par1Str, par2ArrayOfObj);
    075    }
    076
    077    public void logWarningException(String par1Str, Throwable par2Throwable)
    078    {
    079        this.serverLogger.log(Level.WARNING, par1Str, par2Throwable);
    080    }
    081
    082    public void logSevere(String par1Str)
    083    {
    084        this.serverLogger.log(Level.SEVERE, par1Str);
    085    }
    086
    087    public void logSevereException(String par1Str, Throwable par2Throwable)
    088    {
    089        this.serverLogger.log(Level.SEVERE, par1Str, par2Throwable);
    090    }
    091
    092    @SideOnly(Side.CLIENT)
    093    public void logFine(String par1Str)
    094    {
    095        this.serverLogger.log(Level.FINE, par1Str);
    096    }
    097
    098    static String func_98237_a(LogAgent par0LogAgent)
    099    {
    100        return par0LogAgent.loggerPrefix;
    101    }
    102}