Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
package ch.qos.logback.classic.selector.servlet;
A servlet filter that puts the environment dependent LoggerContext in a ThreadLocal variable, removing it after the request is processed.

To use it, add the following lines to a web.xml file <filter> <filter-name>LoggerContextFilter</filter-name> <filter-class> ch.qos.logback.classic.selector.servlet.LoggerContextFilter </filter-class> </filter> <filter-mapping> <filter-name>LoggerContextFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

S├ębastien Pennec
public class LoggerContextFilter implements Filter {
  public void destroy() {
    //do nothing
  public void doFilter(ServletRequest requestServletResponse response,
      FilterChain chainthrows IOExceptionServletException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    ContextSelector selector = ContextSelectorStaticBinder.getSingleton().getContextSelector();
    ContextJNDISelector sel = null;
    if (selector instanceof ContextJNDISelector) {
      sel = (ContextJNDISelector)selector;
    try {
    } finally {
      if (sel != null) {
  public void init(FilterConfig arg0throws ServletException {
    //do nothing
New to GrepCode? Check out our FAQ X