package net.cobem.grizzly.console;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

public class OutputHandler {
    private Logger LogMechanism;

    private String Pattern = "%-5p[%t] %F:%L - %m%n";

    public OutputHandler() {
        LogMechanism = Logger.getLogger(OutputHandler.class.getName());

        LogMechanism.addAppender(new ConsoleAppender(new PatternLayout(Pattern)));
    }

    public void write(String Text, OutputType Type) {
        if (Type == OutputType.Debug) {
            LogMechanism.debug(Text);
        }

        if (Type == OutputType.Info) {
            LogMechanism.info(Text);
        }

        if (Type == OutputType.Warning) {
            LogMechanism.warn(Text);
        }

        if (Type == OutputType.Error) {
            LogMechanism.error(Text);
        }
    }

    public void write(String Class, String Text, OutputType Type) {
        Logger LogByClass = Logger.getLogger(Class);

        LogByClass.addAppender(new ConsoleAppender(new PatternLayout(Pattern)));

        if (Type == OutputType.Debug) {
            LogByClass.debug(Text);
            return;
        }

        if (Type == OutputType.Info) {
            LogByClass.info(Text);
            return;
        }

        if (Type == OutputType.Warning) {
            LogByClass.warn(Text);
            return;
        }

        if (Type == OutputType.Error) {
            LogByClass.error(Text);
            return;
        }
    }
}
