/* ############################################################################### # # # Copyright (C) 2011-2016 OpenMEAP, Inc. # # Credits to Jonathan Schang & Rob Thacher # # # # Released under the LGPLv3 # # # # OpenMEAP is free software: you can redistribute it and/or modify # # it under the terms of the GNU Lesser General Public License as published # # by the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # OpenMEAP is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU Lesser General Public License for more details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with OpenMEAP. If not, see <http://www.gnu.org/licenses/>. # # # ############################################################################### */ package com.openmeap.web.servlet; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.xml.DOMConfigurator; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import com.openmeap.util.Utils; import com.openmeap.util.XmlUtils; public class Log4JConfiguratorListener implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub } @Override public void contextInitialized(ServletContextEvent arg0) { BasicConfigurator.configure(); ServletContext servletContext = arg0.getServletContext(); String xmlLoc = servletContext.getInitParameter("openmeap-log4j-xml"); if( xmlLoc==null ) { return; } try { Resource res = new ClassPathResource(xmlLoc); DOMConfigurator.configure( XmlUtils.getDocument(res.getInputStream()).getDocumentElement() ); } catch(Exception ioe) { servletContext.log("The configuration failed.",ioe); } } }