diff options
author | Henri Herscher <henri@oreka.org> | 2005-10-20 13:46:56 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2005-10-20 13:46:56 +0000 |
commit | 25c5446b5e0ab6d534203097b351699b1a769c6a (patch) | |
tree | 460bce79c944aa65151a358df5bd3c26af35513c /orkweb/src/net/sf/oreka/orkweb | |
parent | 7e1d63dd9fd149e4934bf77095c8610fac786b04 (diff) |
first checkin
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@3 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkweb/src/net/sf/oreka/orkweb')
-rw-r--r-- | orkweb/src/net/sf/oreka/orkweb/ContextListener.java | 71 | ||||
-rw-r--r-- | orkweb/src/net/sf/oreka/orkweb/LogManager.java | 75 |
2 files changed, 146 insertions, 0 deletions
diff --git a/orkweb/src/net/sf/oreka/orkweb/ContextListener.java b/orkweb/src/net/sf/oreka/orkweb/ContextListener.java new file mode 100644 index 0000000..52ab577 --- /dev/null +++ b/orkweb/src/net/sf/oreka/orkweb/ContextListener.java @@ -0,0 +1,71 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orkweb; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import net.sf.oreka.HibernateManager; + +import org.apache.log4j.Logger; + +public class ContextListener implements ServletContextListener { + + Logger log = null; + public static boolean debugSwitch = false; // Enables application debugging (e.g. no login phase) + + public void contextInitialized(ServletContextEvent servletContextEvent) { + + ServletContext context = servletContextEvent.getServletContext(); + String log4jConfigFile = context.getInitParameter("Log4jConfigFile"); + + if (log4jConfigFile == null) { + System.out.println("Log4jConfigFile context-param missing in web.xml"); + } + + LogManager.getInstance().configure(log4jConfigFile); + log = LogManager.getInstance().getRootLogger(); + log.info("========================================"); + log.info("orkweb starting ..."); + + String hibernateConfigFile = context.getInitParameter("HibernateConfigFile"); + if (hibernateConfigFile == null) { + log.error("HibernateConfigFile context-param missing in web.xml"); + } + + try { + HibernateManager.configure(hibernateConfigFile); + } + catch (Exception e) { + log.error("orkweb.ContextListener: Error configuring Hibernate: " + e.getMessage()); + } + + String debugSwitchParm = context.getInitParameter("Debug"); + if (debugSwitchParm != null) { + if(debugSwitchParm.equals("true")) { + debugSwitch = true; + log.warn("Running in debug mode"); + } + else { + debugSwitch = false; + } + } + } + + public void contextDestroyed(ServletContextEvent arg0) { + log.info("orkweb stopping ..."); + log.info("========================================"); + } +}
\ No newline at end of file diff --git a/orkweb/src/net/sf/oreka/orkweb/LogManager.java b/orkweb/src/net/sf/oreka/orkweb/LogManager.java new file mode 100644 index 0000000..4069100 --- /dev/null +++ b/orkweb/src/net/sf/oreka/orkweb/LogManager.java @@ -0,0 +1,75 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.orkweb; + +import java.io.File; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +/** + * This singleton class manages all application log4j loggers + */ +public class LogManager { + + static LogManager logManager = null; + + Logger rootLogger = null; + + + private LogManager() + { + rootLogger = Logger.getRootLogger(); + + BasicConfigurator.configure(); // in case there is no properties file + } + + public static LogManager getInstance() + { + if (logManager == null) + { + logManager = new LogManager(); + } + return logManager; + } + + public void configure(String filename) { + + // Check wether filename is valid + File file = new File(filename); + if (file.exists()) { + // Attempt to configure log4j + PropertyConfigurator.configure(filename); + } + else { + rootLogger.warn("Log4j properties file does not exist:" + filename + " check your web.xml"); + } + } + + /** + * @return Returns the rootLogger. + */ + public Logger getRootLogger() { + return rootLogger; + } + + + /** + * @param rootLogger The rootLogger to set. + */ + public void setRootLogger(Logger rootLogger) { + this.rootLogger = rootLogger; + } +} |