package de.thomasjacob.improve.presentation;

import de.thomasjacob.improve.logic.Logs;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.logging.util.LoggerStream;


public class Log4JInitServlet extends HttpServlet
{
	public void init() throws ServletException
	{
		ServletContext context = this.getServletContext();

		try
		{
			String logFileName = context.getRealPath("WEB-INF/conf/log4j.xml");
			DOMConfigurator.configure(logFileName);

			// catch console output and redirect it to log4j
			Logger stdoutLogger = Logger.getLogger("STDOUT");
			Logger stderrLogger = Logger.getLogger("STDERR");
			new LoggerStream(stdoutLogger);
			new LoggerStream(stderrLogger);
		}
		catch (Exception e) // $codepro.audit.disable caughtExceptions
		{
			BasicConfigurator.configure();
			Logs.LOGIC.error("Exception during init:", e);
		}
	}
}