package be.iminds.ilabt.jfed.highlevel.jobs.report;

import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.helpers.MessageFormatter;

import javax.annotation.Nonnull;

/**
 * User: twalcari
 * Date: 12/9/2015
 * Time: 16:29
 */
public class JobReportWrappingLogger implements org.slf4j.Logger {
    private final org.slf4j.Logger wrappedLog;
    private final JobReport jobReport;

    public JobReportWrappingLogger(@Nonnull Logger wrappedLog, @Nonnull JobReport jobReport) {
        this.wrappedLog = wrappedLog;
        this.jobReport = jobReport;
    }

    @Override
    public String getName() {
        return wrappedLog.getName();
    }

    @Override
    public boolean isTraceEnabled() {
        return wrappedLog.isTraceEnabled();
    }

    @Override
    public void trace(String s) {
        wrappedLog.trace(s);
    }

    @Override
    public void trace(String s, Object o) {
        wrappedLog.trace(s, o);
    }

    @Override
    public void trace(String s, Object o, Object o1) {
        wrappedLog.trace(s, o, o1);
    }

    @Override
    public void trace(String s, Object... objects) {
        wrappedLog.trace(s, objects);
    }

    @Override
    public void trace(String s, Throwable throwable) {
        wrappedLog.trace(s, throwable);
    }

    @Override
    public boolean isTraceEnabled(Marker marker) {
        return wrappedLog.isTraceEnabled(marker);
    }

    @Override
    public void trace(Marker marker, String s) {
        wrappedLog.trace(marker, s);
    }

    @Override
    public void trace(Marker marker, String s, Object o) {
        wrappedLog.trace(marker, s, o);
    }

    @Override
    public void trace(Marker marker, String s, Object o, Object o1) {
        wrappedLog.trace(marker, s, o, o1);
    }

    @Override
    public void trace(Marker marker, String s, Object... objects) {
        wrappedLog.trace(marker, s, objects);
    }

    @Override
    public void trace(Marker marker, String s, Throwable throwable) {
        wrappedLog.trace(marker, s, throwable);
    }

    @Override
    public boolean isDebugEnabled() {
        return wrappedLog.isDebugEnabled();
    }

    @Override
    public void debug(String s) {
        wrappedLog.debug(s);
        jobReport.debug(s);
    }

    private static String makeMsg(String s, Object o) {
        return MessageFormatter.format(s, o).getMessage();
    }
    private static String makeMsg(String s, Object o1, Object o2) {
        return MessageFormatter.format(s, o1, o2).getMessage();
    }
    private static String makeMsg(String s, Object... o) {
        return MessageFormatter.format(s, o).getMessage();
    }

    @Override
    public void debug(String s, Object o) {
        wrappedLog.debug(s, o);
        jobReport.debug(makeMsg(s, o));
    }

    @Override
    public void debug(String s, Object o, Object o1) {
        wrappedLog.debug(s, o, o1);
        jobReport.debug(makeMsg(s, o, o1));
    }

    @Override
    public void debug(String s, Object... objects) {
        wrappedLog.debug(s, objects);
        jobReport.debug(makeMsg(s, objects));
    }

    @Override
    public void debug(String s, Throwable throwable) {
        wrappedLog.debug(s, throwable);
        jobReport.debug(s, throwable);
    }

    @Override
    public boolean isDebugEnabled(Marker marker) {
        return wrappedLog.isDebugEnabled(marker);
    }

    @Override
    public void debug(Marker marker, String s) {
        wrappedLog.debug(marker, s);
        jobReport.debug(s);
    }

    @Override
    public void debug(Marker marker, String s, Object o) {
        wrappedLog.debug(marker, s, o);
        jobReport.debug(makeMsg(s, o));
    }

    @Override
    public void debug(Marker marker, String s, Object o, Object o1) {
        wrappedLog.debug(marker, s, o, o1);
        jobReport.debug(makeMsg(s, o, o1));
    }

    @Override
    public void debug(Marker marker, String s, Object... objects) {
        wrappedLog.debug(marker, s, objects);
        jobReport.debug(makeMsg(s, objects));
    }

    @Override
    public void debug(Marker marker, String s, Throwable throwable) {
        wrappedLog.debug(marker, s, throwable);
        jobReport.debug(s, throwable);
    }

    @Override
    public boolean isInfoEnabled() {
        return wrappedLog.isInfoEnabled();
    }

    @Override
    public void info(String s) {
        wrappedLog.info(s);
        jobReport.info(s);
    }

    @Override
    public void info(String s, Object o) {
        wrappedLog.info(s, o);
        jobReport.info(makeMsg(s, o));
    }

    @Override
    public void info(String s, Object o, Object o1) {
        wrappedLog.info(s, o, o1);
        jobReport.info(makeMsg(s, o, o1));
    }

    @Override
    public void info(String s, Object... objects) {
        wrappedLog.info(s, objects);
        jobReport.info(makeMsg(s, objects));
    }

    @Override
    public void info(String s, Throwable throwable) {
        wrappedLog.info(s, throwable);
        jobReport.info(s, throwable);
    }

    @Override
    public boolean isInfoEnabled(Marker marker) {
        return wrappedLog.isInfoEnabled(marker);
    }

    @Override
    public void info(Marker marker, String s) {
        wrappedLog.info(marker, s);
        jobReport.info(s);
    }

    @Override
    public void info(Marker marker, String s, Object o) {
        wrappedLog.info(marker, s, o);
        jobReport.info(makeMsg(s, o));
    }

    @Override
    public void info(Marker marker, String s, Object o, Object o1) {
        wrappedLog.info(marker, s, o, o1);
        jobReport.info(makeMsg(s, o, o1));
    }

    @Override
    public void info(Marker marker, String s, Object... objects) {
        wrappedLog.info(marker, s, objects);
        jobReport.info(makeMsg(s, objects));
    }

    @Override
    public void info(Marker marker, String s, Throwable throwable) {
        wrappedLog.info(marker, s, throwable);
        jobReport.info(s, throwable);
    }

    @Override
    public boolean isWarnEnabled() {
        return wrappedLog.isWarnEnabled();
    }

    @Override
    public void warn(String s) {
        wrappedLog.warn(s);
        jobReport.warn(s);
    }

    @Override
    public void warn(String s, Object o) {
        wrappedLog.warn(s, o);
        jobReport.warn(makeMsg(s, o));
    }

    @Override
    public void warn(String s, Object... objects) {
        wrappedLog.warn(s, objects);
        jobReport.warn(makeMsg(s, objects));
    }

    @Override
    public void warn(String s, Object o, Object o1) {
        wrappedLog.warn(s, o, o1);
        jobReport.warn(makeMsg(s, o, o1));
    }

    @Override
    public void warn(String s, Throwable throwable) {
        wrappedLog.warn(s, throwable);
        jobReport.warn(s, throwable);
    }

    @Override
    public boolean isWarnEnabled(Marker marker) {
        return wrappedLog.isWarnEnabled(marker);
    }

    @Override
    public void warn(Marker marker, String s) {
        wrappedLog.warn(marker, s);
        jobReport.warn(s);
    }

    @Override
    public void warn(Marker marker, String s, Object o) {
        wrappedLog.warn(marker, s, o);
        jobReport.warn(makeMsg(s, o));
    }

    @Override
    public void warn(Marker marker, String s, Object o, Object o1) {
        wrappedLog.warn(marker, s, o, o1);
        jobReport.warn(makeMsg(s, o, o1));
    }

    @Override
    public void warn(Marker marker, String s, Object... objects) {
        wrappedLog.warn(marker, s, objects);
        jobReport.warn(makeMsg(s, objects));
    }

    @Override
    public void warn(Marker marker, String s, Throwable throwable) {
        wrappedLog.warn(marker, s, throwable);
        jobReport.warn(s, throwable);
    }

    @Override
    public boolean isErrorEnabled() {
        return wrappedLog.isErrorEnabled();
    }

    @Override
    public void error(String s) {
        wrappedLog.error(s);
        jobReport.error(s);
    }

    @Override
    public void error(String s, Object o) {
        wrappedLog.error(s, o);
        jobReport.error(makeMsg(s, o));
    }

    @Override
    public void error(String s, Object o, Object o1) {
        wrappedLog.error(s, o, o1);
        jobReport.error(makeMsg(s, o, o1));
    }

    @Override
    public void error(String s, Object... objects) {
        wrappedLog.error(s, objects);
        jobReport.error(makeMsg(s, objects));
    }

    @Override
    public void error(String s, Throwable throwable) {
        wrappedLog.error(s, throwable);
        jobReport.error(s, throwable);
    }

    @Override
    public boolean isErrorEnabled(Marker marker) {
        return wrappedLog.isErrorEnabled(marker);
    }

    @Override
    public void error(Marker marker, String s) {
        wrappedLog.error(marker, s);
        jobReport.error(s);
    }

    @Override
    public void error(Marker marker, String s, Object o) {
        wrappedLog.error(marker, s, o);
        jobReport.error(makeMsg(s, o));
    }

    @Override
    public void error(Marker marker, String s, Object o, Object o1) {
        wrappedLog.error(marker, s, o, o1);
        jobReport.error(makeMsg(s, o, o1));
    }

    @Override
    public void error(Marker marker, String s, Object... objects) {
        wrappedLog.error(marker, s, objects);
        jobReport.error(makeMsg(s, objects));
    }

    @Override
    public void error(Marker marker, String s, Throwable throwable) {
        wrappedLog.error(marker, s, throwable);
        jobReport.error(s, throwable);
    }
}
