title: Practical use of Logback context selectors
body: <p>The documentation on Logback <a href="http://logback.qos.ch/manual/loggingSeparation.html" rel="noreferrer">logging separation</a> indicates that I can use <a href="http://logback.qos.ch/manual/contextSelector.html" rel="noreferrer">context selectors</a> to create different logging configurations on the same JVM. Somehow a context selector will allow me to call <code>LoggerFactory.getLogger(Foo.class)</code> and, based upon the context, I will get a differently configured logger.</p>
  
  <p>Unfortunately the examples only deal with JNDI in the context of a specially configured web server such as Tomcat or Jetty. I want to know how I can practically use a context selector myself, for example in a non-web application.</p>
  
  <p>My goal is to have more than one logging configuration on the same JVM. Here is one scenario:</p>
  
  <ul>
  <li>I want one thread to get loggers using the default <code>logback.xml</code> configuration on the classpath.</li>
  <li>I want another thread to get loggers using another <code>logback.xml</code> from a custom directory.</li>
  <li>I want a third thread to get loggers from a programmatic configuration.</li>
  </ul>
  
  <p>I provide these example scenarios just to get an idea of <em>practical</em> use of context selectors---how I would do something useful with them in real life.</p>
  
  <ol>
  <li>How could I use context selectors to implement the scenarios above, so that <code>LoggerFactory.getLogger(Foo.class)</code> returns a logger from the correct configuration based on the thread?</li>
  <li>If context selectors are not up to the task, how could I manually get an <code>ILoggerFactory</code> instance that would give me loggers from a programmatic configuration?</li>
  </ol>