/** * Logback: the reliable, generic, fast and flexible logging framework. * * Copyright (C) 1999-2006, QOS.ch * * This library 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. */ package ch.qos.logback.classic.selector.servlet; import org.slf4j.Logger; import org.slf4j.impl.StaticLoggerBinder; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.selector.ContextSelector; public class DefaultContextDetachingSCL implements ServletContextListener { public void contextDestroyed(ServletContextEvent servletContextEvent) { // loggerContextName hardcoded - could be made configurable to support other than "default" name String loggerContextName = "default"; System.out.println("About to detach context named " + loggerContextName); ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector(); // possibly unneccesary to detach for the DefaultContextSelector LoggerContext context = selector.detachLoggerContext(loggerContextName); if (context != null) { Logger logger = context.getLogger(LoggerContext.ROOT_NAME); logger.warn("Stopping logger context " + loggerContextName); // when the web-app is destroyed, its logger context should be stopped context.stop(); } } public void contextInitialized(ServletContextEvent arg0) { // do nothing } }