package utis.wall.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author wonwoolee
 *
 */
public class Log4jdbcLog4j2ConfigListener implements ServletContextListener {

	/**
	 * 
	 */
	public Log4jdbcLog4j2ConfigListener() {}

	/**
	 * @param sce
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ServletContext sc = sce.getServletContext();
		String location = sc.getInitParameter("log4jdbcLog4j2ConfigLocation");
		System.out.println(System.getProperty("java.class.path"));
		if (location != null) {
			// Write log message to server log.
			sc.log("::: Set System Property -> log4jdbc.log4j2.properties.file=" + location);

			// System Property 설정 : log4jbc-log4j2 프로퍼티경로 변경 설정
			System.setProperty("log4jdbc.log4j2.properties.file", location);

		} else {
			sc.log("::: Not Found 'log4jdbcLog4j2ConfigLocation' parameter: log4jdbc.log4j2 properties file will be loaded from default location.");
		}
	}

	/**
	 * @param sce
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent sce) {}
}
