package com.infinityraider.agricraft.impl.v1;

import com.agricraft.agricore.log.AgriLogAdapter;
import com.infinityraider.agricraft.AgriCraft;

import java.text.MessageFormat;
import org.apache.logging.log4j.Level;

public class ModLogger implements AgriLogAdapter {

    public void log(Level logLevel, Object source, String format, Object... objects) {
        try {
            AgriCraft.instance.getLogger().log(Level.INFO, String.valueOf(source), MessageFormat.format(format, objects));
        } catch (IllegalArgumentException ex) {
            // This is bad...
            AgriCraft.instance.getLogger().log(Level.INFO, String.valueOf(source), format);
        }
    }

    @Override
    public void all(Object source, String format, Object... objects) {
        log(Level.ALL, source, format, objects);
    }

    @Override
    public void debug(Object source, String format, Object... objects) {
        if (AgriCraft.instance.getConfig().debugMode()) {
            log(Level.INFO, source, "[DEBUG]: " + format, objects);
        }
    }

    @Override
    public void trace(Object source, Exception e) {
        debug(source, e.getLocalizedMessage());
    }

    @Override
    public void error(Object source, String format, Object... objects) {
        log(Level.ERROR, source, format, objects);
    }

    @Override
    public void info(Object source, String format, Object... objects) {
        log(Level.INFO, source, format, objects);
    }

    @Override
    public void warn(Object source, String format, Object... objects) {
        log(Level.WARN, source, format, objects);
    }

    @Override
    public void severe(Object source, String format, Object... objects) {
        log(Level.FATAL, source, format, objects);
    }

}

@@ -142,40 +142,8 @@
 t;%0A%0A
-import java.text.MessageFormat;%0A
 impo
@@ -382,65 +382,39 @@
 log(
+log
 Level
-.INFO, String.valueOf(source), MessageFormat.format(
+, %22%5B%22 + source + %22%5D%22 + 
 form
@@ -425,17 +425,16 @@
 objects)
-)
 ;%0A      
@@ -556,43 +556,38 @@
 log(
+log
 Level
-.INFO, String.valueOf(source),
+, %22%5B%22 + source + %22%5D%22 +
  for

Fix AgriCore logging