转自:https://veromca273.iteye.com/blog/1889304
1 创建监听器:
- public class LogListener implements ServletContextListener
- {
- private Log log = LogFactoryImpl.getFactory().getLog(LogListener.class);
- @Override
- public void contextDestroyed(ServletContextEvent arg0)
- {
- if (log.isDebugEnable())
- {
- log.debug("销毁LogListener....");
- }
- }
- @Override
- public void contextInitialized(ServletContextEvent arg0)
- {
- // 配置log4j
- String filePath = "src/conf/log4j.xml";
- DOMConfigurator.configure(filePath);
- if (log.isDebugEnable())
- {
- log.debug("初始化Web日志成功....");
- }
- }
2 修改web.xml 注册监听器
-
- <listener>
- <listener-class>com.log.LogListener</listener-class>
- </listener>